Javascript examples for DOM HTML Element:Input Checkbox
The checked property sets or gets the checked state of a checkbox.
This property reflects the HTML checked attribute.
Set the checked property with the following Values
Value | Description |
---|---|
true|false | Sets whether a checkbox should be checked or not. |
A Boolean, returns true if the checkbox is checked, and false if the checkbox is not checked
The following code shows how to set the checked state of a checkbox:
<!DOCTYPE html> <html> <body> Checkbox: <input type="checkbox" id="myCheck"> <button onclick="check()">Check Checkbox</button> <button onclick="uncheck()">Uncheck Checkbox</button> <script> function check() {/*from ww w . ja v a 2s . c o m*/ document.getElementById("myCheck").checked = true; } function uncheck() { document.getElementById("myCheck").checked = false; } </script> </body> </html>