Javascript DOM HTML Input Number value Property set

Introduction

Change the number of a number field:

document.getElementById("myNumber").value = "16";

Click the button to change 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() {/* w w w .ja v  a 2 s.c  o m*/
  document.getElementById("myNumber").value = "16";
}
</script>

</body>
</html>

The value property sets or gets the value attribute of a number field.

The value property accepts and returns a String type value.




PreviousNext

Related