Javascript examples for DOM HTML Element:Input Number
The defaultValue property sets or gets the default value of a number field.
The default value is the value specified in the HTML value attribute.
You can use defaultValue property to find out whether the number of a number field have been changed.
Set the defaultValue property with the following Values
Value | Description |
---|---|
value | Sets the default value of the number field |
A String, representing the default value of the number field
The following code shows how to change the default value of a number field:
<!DOCTYPE html> <html> <body> Number: <input type="number" id="myNumber" value="2"> <button type="button" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* w ww . j a va2 s .com*/ var x = document.getElementById("myNumber"); x.defaultValue = '3'; } </script> </body> </html>