html - Javascript to check a checkbox if an other checkbox is checked -


i have 2 checkboxes, consider chk1 , chk2. if 1 checkbox checked, second checkbox should checked automatically , not viceversa. should javascript? can me? thank you!!

here's simple inline version demonstrate general idea. might want pull out separate function in real world usage.

if want chk2 automatically stay in sync changes chk1, not when chk2 clicked go this.

 <input id="chk1" type="checkbox" onclick="document.getelementbyid('chk2').checked = this.checked;">  <input id="chk2" type="checkbox"> 

this version change chk2 when chk1 checked, not when ck1 unchecked.

 <input id="chk1" type="checkbox" onclick="if (this.checked) document.getelementbyid('chk2').checked = true;">  <input id="chk2" type="checkbox"> 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -