Set a checkbox to be a required part of form submission:
document.getElementById("myCheck").required = true;
Click button to set the required property for the checkbox.
<!DOCTYPE html> <html> <body> <form action="/action_page.php"> Checkbox: <input type="checkbox" id="myCheck" name="test"> <input type="submit"> </form>// ww w .j a v a 2 s. co m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myCheck").required = true; document.getElementById("demo").innerHTML = "The required property was set."; } </script> </body> </html>