Javascript DOM HTML Input Number value Property get

Introduction

Get the number of a number field:

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

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

View 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() {/*from  www. j ava  2 s  .c  o m*/
  var x = document.getElementById("myNumber").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related