The value
property sets or gets the value attribute of a number field.
value |
Yes | 10.0 | Yes | Yes | Yes |
Return the value property.
var v = numberObject.value
Set the value property.
numberObject.value=number
Value | Description |
---|---|
number | Set the value of the number field |
A String type value representing a number.
The following code shows how to use .Get the number of a number field.
<!DOCTYPE html>
<html>
<body>
Number: <input type="number" id="myNumber" value="2">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- ww w . j a v a2 s . c om-->
var x = document.getElementById("myNumber").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the number of a number field.
<!DOCTYPE html>
<html>
<body>
<!--from ww w . j a v a 2s . c om-->
<input type="number" id="myNumber" value="2">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myNumber").value = "16";
}
</script>
</body>
</html>
The code above is rendered as follows: