I am using the following piece of code to check some checkboxes based on their Id and a value stored in a array. So if the array has a value, the corresponding checkbox should become checked.
for($k=0;$k<count($array_ids);$k++){
echo'<script type="text/javascript">
var cb = document.getElementsById("id_'.$array_ids[$k].'");
cb.checked = true;
</script>';
}
And this is the code for the checkboxes:
<input type="checkbox" id="id_'.$array_ids[$k].'" name="'.$array_ids[$k].'" value="checked" class= "My_class" onchange="add_on_textBox(this,\''.$array_ids[$k].'\',\'My_class\')">
And this is the var_dump result for the $array_ids:
array(2) {
[0]=>
string(5) "Name1"
[1]=>
string(5) "Name2"
}
The code doesn't work. I am pretty sure I am missing something.