Get Input Number Field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Introduction

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

You can access an <input> element with type="number" by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="number" id="myNumber" value="2">

<button onclick="myFunction()">get the number of the number field</button>

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

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

</body>
</html>

Related Tutorials