Javascript examples for DOM HTML Element:Input Checkbox
The required property sets or gets whether a checkbox must be checked before submitting a form.
This property reflects the HTML required attribute.
Set the required property with the following Values
Value | Description |
---|---|
true|false | Sets whether a checkbox should be checked before submitting a form |
A Boolean, returns true if the checkbox must be checked before submitting a form, otherwise it returns false
The following code shows how to check if a checkbox must be checked before submitting a form:
<!DOCTYPE html> <html> <body> <form action="#"> Checkbox: <input type="checkbox" id="myCheck" name="test"> <input type="submit"> </form>//from w ww . ja va 2 s. c o m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var v = document.getElementById("myCheck").required; document.getElementById("demo").innerHTML = v; } </script> </body> </html>