Hello Dev,
Today, i we will show you how to Check/Uncheck checkbox in javaScript. This article will give you simple example of how to Check/Uncheck checkbox in javaScript. you will learn how to Check/Uncheck checkbox in javaScript.
So let’s follow few step to create example of how to Check/Uncheck checkbox in javaScript.
Example
<html> <head> <title>How To Check/Uncheck checkbox In JavaScript - Codeplaners</title> </head> <body> <center> <h2>How To Check/Uncheck checkbox In JavaScript - Codeplaners</h2> <form> <div> <input type="button" onclick="checkAll()" value="Check All"> <input type="button" onclick="uncheckAll()" value="Uncheck All"> </div> <label><input type="checkbox" class="check2">First</label> <label><input type="checkbox" class="check2">Second</label> <label><input type="checkbox" class="check2">Third</label> </form> </center> </body> <script type="text/javascript"> //checkall function function checkAll() { var inputs = document.querySelectorAll('.check2'); for (var i = 0; i < inputs.length; i++) { inputs[i].checked = true; } } //uncheckall function function uncheckAll() { var inputs = document.querySelectorAll('.check2'); for (var i = 0; i < inputs.length; i++) { inputs[i].checked = false; } } window.onload = function() { window.addEventListener('load', checkAll, false); } </script> </html>