The value
property sets or gets the value of the value attribute of a checkbox.
value |
Yes | Yes | Yes | Yes | Yes |
Return the value property.
var v = checkboxObject.value
Set the value property.
checkboxObject.value=text
Value | Description |
---|---|
text | Set the value associated with the checkbox |
A String type value representing the value attribute of the checkbox.
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: