1

Basically, when I tab through this form, for every input field the text is highlighted, but this doesn't happen for my textareas. Any help or ideas would be appreciated. I've included my textarea html below just in case.

<textarea onblur="if(this.value==''){this.value='Embed Code'}" onclick="if(this.value=='Embed Code'){this.value=''}" name="post.code">Embed Code</textarea>
Zumwalt
  • 151
  • 1
  • 4
  • 13
  • What do you mean by 'highlighted'? Did you add effects to each input, or are you speaking of the browser's native highlighting that it does all on its own? – Sampson Jul 01 '11 at 01:56
  • Native highlighting. I apologize for the lack of clarification. – Zumwalt Jul 01 '11 at 02:12
  • Is your question about highlighting a field, or replacing the text in a field when you focus on it? – Sampson Jul 01 '11 at 02:14

1 Answers1

2

Use onfocus instead of onclick, as getting focus from tabbing does not dispatch a click event (so the onclick handler isn't called). Note that HTML5 has the placeholder attribute that will do what your script is doing.

To select the text in the textarea, add a handler for the focus event:

<textarea ... onfocus="this.select()" ...

Note that this may annoy users as they don't expect this to happen for textarea elements.

RobG
  • 142,382
  • 31
  • 172
  • 209
  • That `onfocus` handler isn't enough in Chrome. See http://stackoverflow.com/questions/5797539/jquery-select-all-text-from-a-textarea/5797700#5797700 – Tim Down Jul 01 '11 at 09:12