Set focus at the end of textbox while typing - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Set focus at the end of textbox while typing

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*w w  w .jav  a  2  s. c om*/
document.getElementById("focusButton").onclick = function()  {
    var inputElement = document.getElementById("focusText");
    var text = inputElement.value;
    inputElement.value=text;
    inputElement.focus()
}
    }

      </script> 
   </head> 
   <body> 
      <input type="text" id="focusText"> 
      <button id="focusButton">Set Focus</button>  
   </body>
</html>

Related Tutorials