Javascript DOM HTML Input Number Disable and enable

Introduction

Disable and enable a number field:

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<button onclick="disableBtn()">Disable Number Field</button>
<button onclick="enableBtn()">enable Number Field</button>
<script>
function disableBtn() {// w  w w  . j  a  v  a2s .co m
  document.getElementById("myNumber").disabled = true;
}
function enableBtn() {
  document.getElementById("myNumber").disabled = false;
}
</script>

</body>
</html>



PreviousNext

Related