Gregory3
asked on
Linking 2 HTML checkboxes
I have two checkboxes in seperate basic html tables. I'm trying to get an easy javascript if statement to link the two together. So if checkbox1 is checked, so is checkbox2.
Thanks!
Thanks!
<table class="table1">
<tr>
<td>
<input type='checkbox' class='list_item' name="checkbox1" id=2 value=2 onclick='updateLayerVisibility();' />
</td>
</tr>
</table>
<table class="table2">
<tr>
<td>
<input type='checkbox' class='list_item' name="checkbox2" id='2' value=2 onclick='updateLayerVisibility();' />
</td>
</tr>
</table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if (document.getElementsByNam e("checkbo x1")[0].ch ecked) {
document.getElementsByName ("checkbox 2")[0].che cked=true;
}
document.getElementsByName
}
ASKER
Thanks for your responses.
I have a variant of Sar1973's example working, but that is only for checking them both. The trick is getting them both checked and unchecked by clicking either one. Hope that makes sense.
EddieShipman I like your ternary operator example but I can't get it to jive with my function.
I have a variant of Sar1973's example working, but that is only for checking them both. The trick is getting them both checked and unchecked by clicking either one. Hope that makes sense.
EddieShipman I like your ternary operator example but I can't get it to jive with my function.
Did you try my example?
ASKER
Sorry about that, I missed that one. That worked! Much appreciated.
You're welcome. Glad it worked.
Once you get that squared away, you can do something this in your function:
Open in new window