Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing a checkbox 2

Status
Not open for further replies.

jags22

Programmer
Oct 17, 2001
44
US
I have a group of checkboxes that has several items in it. As an example, if there are 4 items and the last item is a checkbox called None. If none is selected, I want to be able to uncheck any of the other boxes. Also, if they then check one of the other boxes I want to be able to uncheck the None box. I am sure there is a simple example someone knows but I am new to javascript, and am still learning the syntax. Thanks...[bigglasses]
 
Because, there can be multiple inputs that can be true. For example, what kind of car would you like to own?
1. corvette
2. porsche
3. viper
4. none of the above

if they hit none I want to be able to uncheck any of the boxes they have already checked. I hope this explains it better.
 
you can use onchange to trigger events. on each element you can have onchange="myFunction(this)"

and then in your function you could use the element's values and status to affect your other checboxes.

for example

function myFunction(element)
{
if (element.checked) // means it was checked
{
document.getElementById("otherCheckBox").checked = false;
}
}

get the point? :) Gary Haran
 
function checkAll(field)
{
field[4].checked = false;
}

function uncheckAll(field)
{
for(i = 0; i < field.length -1; i++)
field.checked = false;
}






<form name=&quot;myform&quot;>
<input type=&quot;checkbox&quot; name=&quot;list&quot; value=&quot;1&quot; onclick=&quot;checkAll(document.myform.list);&quot;><br>
<input type=&quot;checkbox&quot; name=&quot;list&quot; value=&quot;2&quot; onclick=&quot;checkAll(document.myform.list);&quot;><br>
<input type=&quot;checkbox&quot; name=&quot;list&quot; value=&quot;3&quot; onclick=&quot;checkAll(document.myform.list);&quot;><br>
<input type=&quot;checkbox&quot; name=&quot;list&quot; value=&quot;4&quot; onclick=&quot;checkAll(document.myform.list);&quot;><br>
<input type=&quot;checkbox&quot; name=&quot;list&quot; value=&quot;5&quot; onclick=&quot;uncheckAll(document.myform.list);&quot;><br>
</form>
 
Thanks guys I have it working just like I want because of your tips. Peace [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top