I have here a number of checkboxes. just like this:
<div id = 'fCheck'> <input type="checkbox" id="mango" value="mango" /> <label>MANGO</label><br> <input type="checkbox" id="santol" value="santol" /> <label>SANTOL</label><br> <input type="checkbox" id="guava" value="guava" /> <label>GUAVA</label><br> <input type="checkbox" id="lomboy" value="lomboy" /> <label>LOMBOY</label><br> <input type="checkbox" id="apple" value="apple" /> <label>APPLE</label><br> <input type="checkbox" id="orange" value="orange" /> <label>ORANGE</label><br> </div> and I also have this data:
SupplierID fruit_name Granted 10792 "mango" "Y" 10792 "santol" "Y" 10792 "guava" "N" 10792 "lomboy" "N" 10792 "apple" "Y" 10792 "orange" "Y" Now, what Im trying to do is that everytime I input that supplierID 10792 (through ajax call), all the fruits that has a Y in granted field, will be shown in the through the checkbox above, while the N will left unchecked. Can please help me out? Checking the checkboxes based on granted yes or no is problem. thanks
My ajax call:
var params = { "SessionID": $.cookie("SessionID"), "dataType":"data" }; $.ajax({ type: 'GET', url: 'processjson.php?' + $.param({path:'supplier/view',json:JSON.stringify(params)}), dataType: primeSettings.ajaxDataType, success: function(data) { if ('error' in data) { showMessage('ERROR: ' + data["error"]["msg"]); } else{ $.each(data['result']['main']['rowdata'], function(rowIndex, rowDataValue) { var groupFlag=0; $.each(rowDataValue, function(columnIndex, rowArrayValue) { var fldName = data['result']['main']['metadata']['fields'][columnIndex].name; if (fldName == 'supplier_id'){ supplierID = rowArrayValue; //alert(rightCode); if (supplierID == SupID){//check if the supplier found groupFlag=1; } } if (fldName == 'fruit_name'){ fruitname = rowArrayValue; } if (fldName == 'granted'){ grant = rowArrayValue; if (groupFlag ==1){ if (hasRight == 'y') $('#dialogUserGroupEdit').append('<input type="checkbox" id="'+ rightGroupCode +'" value="'+ rightDesc +'" /> <label>'+rightDesc+'</label><br>'); //must check the checkbox here that have the same fruit_name in the html } } }); }); } } })