Javascript Reference - HTML DOM Input Checkbox value Property








The value property sets or gets the value of the value attribute of a checkbox.

Browser Support

value Yes Yes Yes Yes Yes

Syntax

Return the value property.

var v = checkboxObject.value 

Set the value property.

checkboxObject.value=text

Property Values

Value Description
text Set the value associated with the checkbox




Return Value

A String type value representing the value attribute of the checkbox.

Example

The following code shows how to change the value associated with the checkbox.


<!DOCTYPE html>
<html>
<body>
A Checkbox: <input type="checkbox" id="myCheck" value="myvalue">
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>
<script>
function display() {
    var x = document.getElementById("myCheck").value;
    console.log("The value is: " + x);
}<!--from  w ww.  j  av  a2  s.  c om-->

function change() {
    var x = document.getElementById("myCheck").value = "newCheckboxValue";
    console.log("The value was changed to: " + x);
}
</script>

</body>
</html>

The code above is rendered as follows: