Jump to content
  • Advertisement
Sign in to follow this  
RetroBilly

[web] Check all check boxes when one is checked and then uncheck when it's not.

This topic is 3018 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a javascript function that is suppose to check all check boxes in a list when the main check box is checked then when it's unchecked it unchecks all of the check boxes in the list. The problem is that the code I wrote only seems to check the boxes not uncheck them... I'm calling the function when the onclick event occurs. Here is the source:
<script type="text/javascript">

function CheckAll(chk)
{
  if( document.getElementById("all").checked == true )
  {
    for (i = 0; i < chk.length; i++)
    chk.checked = false;
  }
  else
  {
    for (i = 0; i < chk.length; i++)
    chk.checked = true;
  }
}
</script>

Share this post


Link to post
Share on other sites
Advertisement
I may be a little bit rusty at javascript but it looks like you have it backwards. When all the elements should be checked it is setting them to false (if .checked == true ... i.checked = false) and when all elements should be unchecked it is setting them to true. Try flipping your true and false assignments.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragonsoulj
I may be a little bit rusty at javascript but it looks like you have it backwards. When all the elements should be checked it is setting them to false (if .checked == true ... i.checked = false) and when all elements should be unchecked it is setting them to true. Try flipping your true and false assignments.


Yeah sorry that was for testing, I did find the problem though and it has nothing to do with that function...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!