Input Number value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Description

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

Return Value

A String, representing a number

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

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials