So I have a problem with my site. I have a function where all the checkboxes were supposed to be checked but the only one checked is the first checkbox.
Here's the code for my javascript:
function checkAll() {
var boxes = document.getElementById('myform').getElementsByTagName('input');
for (var i = 0; i < boxes.length; i++) {
if (boxes[i].type == 'checkbox' && boxes[i].id!='checkall'){
boxes[i].checked = true;
document.getElementById('check_'+ boxes[i].value).style.background = '#FFFFCC';
}
}
}
function clearAll() {
var boxes = document.getElementById('myform').getElementsByTagName('input');
for (var i = 0; i < boxes.length; i++) {
if (boxes[i].type == 'checkbox' && boxes[i].id!='checkall'){
boxes[i].checked = false;
document.getElementById('check_'+ boxes[i].value).style.background = '';
}
}
}
and here's for the php code:
print"<form name='myform' id='myform'>
<table border=1><tr><td><td>email<td>password";
while($record=mysql_fetch_array($result))
{
$a=$record['email'];
$b=$record['pwd'];
print"
<tr><td><input type='checkbox' value=$a name=item[]>
<td>$a<td>$b
<td><a href=edit.php?email=$a&pwd=$b><img src=edit.png width=25 height=25></a>
<td><a href=delete.php?email=$a&pwd=$b'><img src=delete.png width=25 height=25></a>";
}
print '</table><input type=submit value=delete name=delete>
<input type="checkbox" id="checkall" name="checkall" onclick="if(this.checked) checkAll(); else clearAll();" />Select All</form>';
I really wonder what's wrong with the function. Thanks in advance guys!
Edit: I've finally managed to solve my own problem, thank you for bothering to those who comment!