Javascript examples for DOM HTML Element:Input Number
The value property sets or gets the value attribute of a number field.
Set the value property with the following Values
Value | Description |
---|---|
number | Sets the initial (default) value of the number field |
A String, representing a number
The following code shows how to change 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 av a2 s . c o m*/ document.getElementById("myNumber").value = 10; document.getElementById("demo").innerHTML = 'changed'; } </script> </body> </html>