Johnmitchell Posted September 28, 2006 Share Posted September 28, 2006 i have following code: <textarea rows="10" cols="30" ID="Textarea1" NAME="Textarea1">Type the text here</textarea> my question is, when a user clicks on the text area, how do i get the text to dissapear? Link to comment Share on other sites More sharing options...
skym Posted September 28, 2006 Share Posted September 28, 2006 Did not test it, but it will probably work: <textarea rows="10" cols="30" ID="Textarea1" NAME="Textarea1" onclick="this.innerHTML='';">Type the text here</textarea> Link to comment Share on other sites More sharing options...
justsomeguy Posted September 28, 2006 Share Posted September 28, 2006 That will work, but it will always delete the text whenever they click on it (even if they just typed their life story). So, a little more robust function may be necessary: function clear_textarea1 (){ if (document.getElementById("Textarea1").innerHTML = "Type the text here") document.getElementById("Textarea1").innerHTML = "";}...<textarea rows="10" cols="30" ID="Textarea1" NAME="Textarea1" onclick="clear_textarea1();"> Link to comment Share on other sites More sharing options...
holmedwa04 Posted September 28, 2006 Share Posted September 28, 2006 Dont you need to use an onblur function, here is the code that I use: <TEXTAREA NAME="Your Name" ROWS="Height in rows" COLS="Width in columns (letters)" style="font-family: arial;" onfocus="if (this.value=='Your text here, dont use apostrophies, as it won't work, unless you use the character code') {this.value='';}" onblur="if (this.value=='') {this.value='Same again, your text here, dont use apostrophies, as it won't work, unless you use the character code';}">Same again, your text here, dont use apostrophies, as it won't work, unless you use the character code.</TEXTAREA>I have highlighted all the bits you need to change, in bold, so when you click the box the text will disapperar, but when you click back it appears again. Just a warning , dont use appostrophies, as it messes up the code, use the character code instead. Link to comment Share on other sites More sharing options...
Johnmitchell Posted September 29, 2006 Author Share Posted September 29, 2006 Cheers for that, someguy's solution was easiest to understand, and easiest to implement and thus easier. w00t bloggeh here i come! Link to comment Share on other sites More sharing options...
holmedwa04 Posted September 29, 2006 Share Posted September 29, 2006 But I was certain justsomeguys suggestion didn't add the text back when you clicked off? I had put the bits you needed to change in bold, and wrote what you needed to put.Oh well, nevermind, im sure you will use whatever is best for you, we all do what we think is right, and so i really don't mind. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now