Return the value attribute of a checkbox:
var x = document.getElementById("myCheck").value;
Click button to display the value attribute of the checkbox.
<!DOCTYPE html> <html> <body> Checkbox: <input type="checkbox" id="myCheck" value="myvalue"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from www . j av a 2 s . c om var x = document.getElementById("myCheck").value; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The value
property sets or gets the value attribute of a checkbox.
For checkboxes, the value property does not appear in the web page.
If a checkbox is in checked state when the form is submitted, the name of the checkbox is sent with the value property.
If the checkbox is not checked, no information is sent.
The value
property accepts and returns a String value.