Darkmatter5 Posted November 19, 2008 Share Posted November 19, 2008 I have 5 check boxes and I need for if a specific one is checked all the others uncheck. I see on a lot of sites a button that when clicked checks all boxes, but I would like for a checkbox being checked to activate this script of unchecking the other check boxes. How can I do this? Quote Link to comment Share on other sites More sharing options...
BoltZ Posted November 19, 2008 Share Posted November 19, 2008 Do you mean like (checkbox) Yes I would like to subscribe to all of these (checkbox) magazine 1 (checkbox) magazine 2 (checkbox) magazine 3 (checkbox) magazine 4 and when they check Yes I would like to subscribe to all of these then it will check/uncheck all of those? To do that you use this code <script type="text/javascript"> function radio() { if(document.form1.radio.checked == false) { document.form1.radio.checked = true; } else (document.form1.radio.checked == true) { document.form1.radio.checked = false; } } </script> Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 19, 2008 Share Posted November 19, 2008 He asked to have all the other field unchecked if the particular field was checked. This will do that, as well as disable the fields when unchecked. <html> <head> <script type="text/javascript"> function uncheckAll(uncheckAll_switch) { //Uncheck all boxes if option checked if (uncheckAll_switch) { document.getElementById('check1').checked = false; document.getElementById('check2').checked = false; document.getElementById('check3').checked = false; document.getElementById('check4').checked = false; } //Disable/Enable all the checkboxes document.getElementById('check1').disabled = uncheckAll_switch; document.getElementById('check2').disabled = uncheckAll_switch; document.getElementById('check3').disabled = uncheckAll_switch; document.getElementById('check4').disabled = uncheckAll_switch; return; } </script> </head> <body> <input type="checkbox" name="clear_all" id="clear_all" onclick="uncheckAll(this.checked);"> Check here to uncheck all other boxes <br><br> <input type="checkbox" name="check1" id="check1"> Checkbox 1<br> <input type="checkbox" name="check2" id="check2"> Checkbox 2<br> <input type="checkbox" name="check3" id="check3"> Checkbox 3<br> <input type="checkbox" name="check4" id="check4"> Checkbox 4<br> </body> </html> Quote Link to comment Share on other sites More sharing options...
BoltZ Posted November 19, 2008 Share Posted November 19, 2008 Oh well thats why I asked if thats what he was asking before posting my code. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 20, 2008 Share Posted November 20, 2008 Oh well thats why I asked if thats what he was asking before posting my code. Actually I misread your response. Your code does uncheck the "child" field when the "parent" is checked. But, it also checks the "child" when the "parent" is unchecked. Not sure if that was what he wanted. But, then again, not enough specifics were given. Quote Link to comment Share on other sites More sharing options...
BoltZ Posted November 20, 2008 Share Posted November 20, 2008 Yea that was my point. Actually I misread your response. Lets call it even Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.