Can I get some ideas or an example of how I could populate the checked state of radio buttons depening on data loaded from the database?
For example I am generating an array from a SELECT query that looks like:
array(
[0] => array(
['note_id'] => 1
['value'] => 'no'
)
[1] => array(
['note_id'] => 4
['value'] => 'yes'
)
[2] => array(
['note_id'] => 5
['value'] => 'yes'
)
)
The checkbox groups look like :
<input type="radio" name="1" value="yes">
<input type="radio" name="1" value="no">
<input type="radio" name="1" value="done">
<input type="radio" name="2" value="yes">
<input type="radio" name="2" value="no">
<input type="radio" name="2" value="done">
Now using json_encode I put the data array of results into :
[{"note_id":"1","value":"no"},{"note_id":"4","value":"yes"},{"note_id":"5","value":"yes"}]
I am passing these results back through ajax.. something like ? :
$j.ajax({
url: readurl,
type: "GET",
data: 'sku=' + thisSku,
dataType: "json",
success: function (data){
// ? now what
}
});
Can someone help me understand how I now could take the json data to select the appropriate choices? How would I create the loop that runs the check if note_id matches the input [name] attribute and if so check the button with the appropriate value? Is json even the best way to handle this? Should I be using .getJSON()?
Inside the success callback you can simply iterate over
datawhich should be[{"note_id":"1","value":"no"},{"note_id":"4","value":"yes"},{"note_id":"5","value":"yes"}].DEMO