views:

876

answers:

1

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

+2  A: 

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.

dommer
Thanks, that works great. Quick followup, I want to put some javascript to be copy and pasted within the textbox, but it seems to be messing it up, is there a way to do this with javascript text inside it?
nm I got it, a simple double quote to single quote seems to have fixed it.