Check if checkbox is checked, if not check it - Javascript

I want to use javascript to check if the Checkbox field is checked. If it is not checked, then the script has to check it. I also would like to create an inverse function that will uncheck the Checkbox, when it is checked. Can you give me advice how to do it ?
0
give a positive ratinggive a negative rating
Hi,

This solution explains how the checking works on event:

<input type="checkbox" id="a1" />

<a href="javascript:void(0);" onClick="javascript: if(document.getElementById('a1').checked==true){ document.getElementById('a1').checked=false; } else{ document.getElementById('a1').checked=true; } " >Check</a>


To check and uncheck the checkbox on event, you can also use this solution:

<input type="checkbox" id="b1" />

<a href="javascript:void(0);" onClick="javascript: document.getElementById('b1').checked= !document.getElementById('b1').checked; " >Check</a>
Share on FacebookShare on TwitterShare on LinkedInSend email
1 answer
x
x
2024 AnswerTabsTermsContact us