HTML textbox, auto highlighting text

15,352

If I've understood your problem correctly, you could use some javascript (untested code):

<script language="JavaScript">
  function selectText(textField) 
  {
    textField.focus();
    textField.select();
  }
</script>

<input type="text" name="sometext" size="100" value="The Text" onClick='selectText(this);'>

You can put the script between your <head> and </head> tags.

Share:
15,352
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    How would I make a textbox, containing preexisting text, that when the user clicked within it all the text inside it would become highlighted. For example, the same way YouTube does the textboxes for the embed code on their videos. Thanks