Unfocus/focus a textbox - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Unfocus/focus a textbox

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body>
       Name: /*w ww .  j  ava  2s . c o  m*/
      <input type="text" id="myText"> 
      <p>Click the button to unfocus the text field.</p> 
      <button onclick="myFunction()">Unfocus input</button> 
      <script>
document.getElementById("myText").focus();

function myFunction() {
    document.getElementById("myText").disabled = true;
    document.getElementById("myText").disabled = false;
}

      </script>  
   </body>
</html>

Related Tutorials