I got 3 checkboxes: 1) All Types 2) Type 1 3) Type 2 If Type 1 or Type 2 is ticked then All Types should get unticked (if it is ticked) If All Types is ticked then all other boxes should get unticked (if any are ticked) All 3 checkboxes need to share the same NAME attribute. Can someone provide a basic solution to acheive this functionality?
Do you want only one of them to be made selected? If so then use Radio buttons. It allows only one to be selected at a time.. If I've misunderstood your problem, please elaborate a bit with example
Nope I require multiple selections. So 'Type 1' and 'Type 2' can be selected together but 'All Types' cannot be selected if any of the other options have been selected.
A very simple example for it <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Check/Uncheck</title> </head> <script> function check_uncheck(){ if(document.getElementById("all_types").checked){ document.getElementById("type1").checked="checked"; document.getElementById("type2").checked="checked"; }else{ document.getElementById("type1").checked=""; document.getElementById("type2").checked=""; } } function is_all_checked(){ if(document.getElementById("type1").checked && document.getElementById("type2").checked){ document.getElementById("all_types").checked="checked"; } if(!document.getElementById("type1").checked || !document.getElementById("type2").checked){ document.getElementById("all_types").checked=""; } } </script> <body> <div>All Types<input type="checkbox" id="all_types" name="all_types" onclick="check_uncheck();"></div> <div>Type 1<input type="checkbox" id="type1" name="type1" onclick="is_all_checked();"></div> <div>Type 2<input type="checkbox" id="type2" name="type2" onclick="is_all_checked();"></div> </body> </html> Code (markup):
The thing is that was a very simplified example that I provided, in reality I have around 10+ checkboxes, is there a way of dynamically doing this rather than hardcoding in each checkbox id?