Javascript DOM HTML Input Number defaultValue Property get

Introduction

Get the default value of a number field:

var x = document.getElementById("myNumber").defaultValue;

Click the button to display the default value of the number field.

View in separate window

<!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 va 2 s. c  om
  var x = document.getElementById("myNumber").defaultValue;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related