Javascript DOM HTML Input Number Object get

Introduction

The Input Number object represents an HTML <input> element with type="number".

We can access an <input> element with type="number" via document.getElementById():

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

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

View in separate window

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

<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {//from   w  w w .j av a  2  s  . c  om
  var x = document.getElementById("myNumber").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related