<input type="checkbox" name="option1" value="one" checked> one<br> <input type="checkbox" name="option2" value="two"> two<br> <input type="checkbox" name="option3" value="two"> tree<br> HTML: Lets say I have three checkboxes. If the first checkbox is checked the other cannot. So, when they select the second or third checkbox, the first one should be automatically unchecked. Is that possible? Please note that the second and third checkbox can be both checked at the same time. First one is checked by default.
I would suggest using Radio instead of checkbox unless there is a strong reason behind it. changing above code something like below will solve the purpose.. <input type="radio" name="option[]" value="one" checked> one<br> <input type="radio" name="option[]" value="two"> two<br> <input type="radio" name="option[]" value="two"> tree<br> HTML: If at all you have to do it using checkbox only, then javascript will have to do the trick
I thought checkboxes would be the best choice because I need to be able to have more than one checkbox checked at the same time. But not with the first one... Example: <input type="checkbox" name="option1" value="one" > one<br> <input type="checkbox" name="option2" value="two" checked> two<br> <input type="checkbox" name="option3" value="two" checked> tree<br> but not: <input type="checkbox" name="option1" value="one" checked> one<br> <input type="checkbox" name="option2" value="two" checked> two<br> <input type="checkbox" name="option3" value="two" checked> tree<br> But I guess I can make more options and just make radios. mastermunj - you've been very helpful in multiple topics of mine Thanks. Any ideas about the "Would I be able to do this?" topic?
Excuse me, may be not related question. What is target.nodeType == 3? What means == 3? I changet it to 2 or 20 and script works in the same way (no differences)
Great code. However I noticed a minor thing: if ((el==ck2) || (el==ck2)) { ck1.checked = false; } I think this should be: if ((el==ck2) || (el==ck3)) { ck1.checked = false; } You've probably already noticed this.