I have a string split by commas. I use the javascript command split to break it into an array.
I have a group of checkboxes called ciContact.
<table border="0" cellspacing="0" cellpadding="6">
<tr>
<td><label>
<input type="checkbox" name="ciContact[]" value="Call" id="ciContact_0" />
Call</label></td>
<td><label>
<input type="checkbox" name="ciContact[]" value="Email" id="ciContact_1" />
Email</label></td>
<td><label>
<input type="checkbox" name="ciContact[]" value="Text" id="ciContact_2" />
Text</label></td>
</tr>
</table>
The array contains just the values that need to be checked. These values are echoed back from an AJAX call that is JSON-encoded. However, these values (ciContact) are all stored in the MySQL database as a comma-delimited array. There is a reason I did it that way. So how do I read the values of my comma-delimited array and check the appropriate checkboxes?
I’ve tried:
var ciContact = data.split(", ");
for (var j = 0; j < ciContact.length; j++)
{
var selected = $('name=ciContact').find('value='+ ciContact[i]);
selected.attr("checked","checked");
}
I’m way off on that one. Ha!
Thanks guys!
Or, for slightly better performance:
Or, fancy: