HTML text box, auto highlight text

How can I make a text box containing existing text that when the user clicks inside it, all the text inside it will be highlighted. For example, the same way YouTube creates text boxes for code to embed their videos. Thanks

+5
source share
1 answer

If I understand your problem correctly, you can use some javascript (unverified 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 a script between your <head> and </head> tags.

+10
source