Javascript DOM HTML Input Text disable and enable

Introduction

Disable and enable a text field:

View in separate window

<!DOCTYPE html>
<html>
<body>

First Name: <input type="text" id="myText" value="Mickey"><br>

<button onclick="disableTxt()">Disable Text field</button>
<button onclick="enableTxt()">enable Text field</button>

<script>
function disableTxt() {/*from   ww  w .  j av a 2  s.c o  m*/
  document.getElementById("myText").disabled = true;
}

function enableTxt() {
  document.getElementById("myText").disabled = false;
}
</script>

</body>
</html>



PreviousNext

Related