text clear

java , javascript Indonesia
  • 12 years ago

    how to select and clear the text  if the text box has intialized value and focus in the text box   in java script

  • 12 years ago

    Let's say you have this textbox in your page:

     <input type="text" id="NameTextBox" />

     

     And in your script:

    <script type="text/javascript">

    var textbox = document.getElementById("NameTextBox");

    textbox.focus(); /* add focus to the textbox */

    textbox.select(); /* select the text content inside the textbox */

    textbox.value = ''; /* clear the text rom the textbox */

    </script>

     

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson