<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>
[web] Check all check boxes when one is checked and then uncheck when it's not.
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:
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.
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.<!--QUOTE--></td></tr></table></BLOCKQUOTE><!--/QUOTE--><!--ENDQUOTE--><br><br>Yeah sorry that was for testing, I did find the problem though and it has nothing to do with that function...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement