Input Number defaultValue Property - Javascript DOM HTML Element

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

Return Value

A String, representing the default value of the number field

The following code shows how to change the default value of a number field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
Number: <input type="number" id="myNumber" value="2">

<button type="button" onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {/*  w ww  . j  a va2  s .com*/
    var x = document.getElementById("myNumber");
    x.defaultValue = '3';


Related Tutorials