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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS for checkboxA to trigger checkboxB to be checked also

Status
Not open for further replies.

mb224

Programmer
Oct 15, 2004
55
US
Using ASP.NET HTML server controls .... need help with javascript for when checkboxA is checked to trigger checkboxB to be automatically checked also.
 
this should do it:

Code:
<form>
<input type="checkbox" name="cbA" onclick="this.form.cbB.checked=this.checked;" />
<input type="checkbox" name="cbB" />
</form>

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
thanks ... I will try it later .. but does this mean that cbB is only checked when cbA is checked, right? (i mean not just clicked)

when cbA is UNchecked say, nothing happens to cbB, right?
 
if you only want it to CHECK checkbox b and not UNCHECK it, you can do this:

Code:
<form>
<input type="checkbox" name="cbA" onclick="if(this.checked)this.form.cbB.checked=this.checked;" />
<input type="checkbox" name="cbB" />
</form>

note, sometimes people tab through field elements and use the spacebar to check checkboxes. in this case you'd need to capture the event in that manner as well. i would suggest writing a function with the code i've already given you to account for that.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top