Link to home
Start Free TrialLog in
Avatar of matreece
matreece

asked on

onclick text disappears

I'm trying to get the below text 'Submit your 24 words here' to disappear when someone clicks in the box.
Can anyone show me how its done please?

<textarea name="words24" id="words24" rows="6" cols="40" tabindex="7">&nbsp;Submit your 24 words here...</textarea>
Avatar of arantius
arantius

<textarea name="words24" id="words24" rows="6" cols="40" tabindex="7" onclick="javascript:this.value='';">&nbsp;Submit your 24 words here...</textarea>
ASKER CERTIFIED SOLUTION
Avatar of Saqib Khan
Saqib Khan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi matreece,
<textarea name="words24" id="words24" rows="6" cols="40" tabindex="7" onclick="this.value=''">&nbsp;Submit your 24 words here...</textarea>

Wimthepimscake
Avatar of matreece

ASKER

Cheers guys for all of your quick responses.
the user can enter the textarea by tabbing so it's better to use onfocus instead of onclick:
<textarea name="words24" id="words24" rows="6" cols="40" tabindex="7" onfocus="this.value=''">&nbsp;Submit your 24 words here...</textarea>

but you'll still have a problem : if user exits the field, and then return to it, the text he wrote will disappear so, even better:

<textarea name="words24" id="words24" rows="6" cols="40" tabindex="7" onfocus="if (this.getAttribute('alreadyWritten')==0) this.value='';" onchange="this.setAttribute('alreadyWritten',1);" alreadyWritten="0">&nbsp;Submit your 24 words here...</textarea>

hope it helps

alambres
Didn't think of that - thats a lot better.
Many thanks.
Here is another working solution!

Asp Textbox
<asp:TextBox runat="server" id="TextBox1" style="color:#999;" value="Enter here!!!" onblur="this.value = this.value || this.defaultValue; if (this.value == this.defaultValue) this.style.color = '#999';" onfocus="if (this.value == this.defaultValue) this.style.color = '#000';if (this.value == this.defaultValue) this.value='';"></asp:TextBox>

For simple html
<input runat="server" id="TextBox2" style="color:#999;" value="Enter here!!!" onblur="this.value = this.value || this.defaultValue; if (this.value == this.defaultValue) this.style.color = '#999';" onfocus="if (this.value == this.defaultValue) this.style.color = '#000';if (this.value == this.defaultValue) this.value='';"/>