Posts: 65
Location: san francisco, ca
|
I am experiencing the same obstacle as the OP. So i would love to have seen the code used that solved it for them...
I have a group of checkboxes that i need to behave like radios, where only one at a time from the group can be checked at any one time. Checking one unchecks all others.
I cant use radios because i need the user to be able to remove their check, without having to use an UNCHECK ALL command. Once a radio from a group is clicked, users cannot uncheck.
Here's the JS i've found that seems promising...
Code:
<script type="text/javascript">
function unCheck(el, n){
el.form.elements[n].checked = false;
}
</script>
And here's a base example of a 3x checkbox group.
Code:
<input type="checkbox" id="check1" onclick="unCheck(this, 'check2','check3');">
<br>
<input type="checkbox" id="check2" onclick="unCheck(this, 'check1','check3');" >
<br>
<input type="checkbox" id="check3" onclick="unCheck(this, 'check1','check2');" >
Functionally, i can still check >1 box in this example. Only the 1st checkbox listed in the onclick is getting unchecked. Which may be a matter of syntax: how to pass >1.
But seeing as though i may have as many as 12x checkboxes (working with Months), is there a more efficient way to have any 1 checkbox uncheck all others? Just like a radio group would behave? Except for the ability for the user to uncheck?
Thanks...
|