Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question
Did you try firebug or chrome dev tools console to check for errors? you can also set breakpoints and debug the code with it. – Kyborek Feb 28 at 11:26
Your html markup has too many errors - wrong tags, missing quotes etc. – enenen Feb 28 at 11:28
error like what? – user2119308 Feb 28 at 11:31
Better use jquery for such tasks it will reduce your code length, increase readability. – Prasanth Bendra Feb 28 at 11:34
1  
Post your solution as an answer. This is not a forum, and we don't mark questions as [SOLVED], like you saw everywhere else. Also, you don't say what you actually did, so your question becomes useless and might be candidate for deletion. – Damien Pirsy Feb 28 at 11:40
show 1 more comment

closed as too localized by Ben, Kami, Brad Larson Feb 28 at 18:37

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.