I want to change checkbox follow JSON string . But i don't know how do it . This is me JSON string, "1" is mean checked and "0" is mean unchecked
[{"Group_Product":"G04","Orange":1,"Banana":0,"Apple":1,"Candy":0,"Food":1}]
And html code.
<table id=table_product>
<tr><td><input type="checkbox" class="checkbox1" id="Orange" name="check[]" />Orange</td></tr>
<tr><td><input type="checkbox" class="checkbox1" id="Banana" name="check[]" />Banana</td></tr>
<tr><td><input type="checkbox" class="checkbox1" id="Apple" name="check[]" />Apple</td></tr>
<tr><td><input type="checkbox" class="checkbox1" id="Candy" name="check[]" />Candy</td></tr>
<tr><td><input type="checkbox" class="checkbox1" id="Food" name="check[]" />Food</td></tr>
</table>
Ok , i use this ways.I'll get name and value in Object JSON, then compare with id of checkbox and checked it.
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var obj = jQuery.parseJSON(data.d);
for (var item in obj[0]) {
if (item.valueOf > 0) {
document.getElementById(item).checked = true;
}
}
},
error: function (data) {
console.log(data.d);
}
If you have a idea or solution, share with me.