Home › Forums › JavaScript › [Solved] Remove default text from text area
- This topic is empty.
-
AuthorPosts
-
July 16, 2010 at 12:05 pm #29646
tomasjj11
MemberHi
I need some help. I would firstly like to say I’ve only really just started out with javascript. I have a form which consist of 2 input text boxes, a textarea and a submit button.
I Found some javascript from http://www.yourhtmlsource.com/forms/cle … ttext.html this removed the text in the value attribute of the text boxes. As I can understand what it is doing when I read the javascript but I don’t know where to start to constructing some code to remove the text from the textarea on focus and apply it back if nothing has been written. The site I am working on is here http://www.flow23.co.uk/tomTesterbedry/.
If anyone can help with either editing the javascript what is currently there or add a new function to achieve the wanted affect.
Any help will be highly appreciated.
July 17, 2010 at 11:05 pm #79895Makeshift
Memberhttp://css-tricks.com/snippets/jquery/clear-default-search-string-on-focus/
This should be what you’re looking for.
September 16, 2010 at 8:44 am #79483tomasjj11
MemberHi there I fixed the problem. I didn’t use makeshift’s Jquery suggestion thank you though.
The javascript source from http://www.yourhtmlsource.com/forms/cle … ttext.html was huge in comparison to what I found can do exactly the same thing. The code is very simple and works in the input form fields and the text area field. The code is onfocus=”if(this.value == ‘Name’) { this.value = ”; }” onblur=”if(this.value == ”) {this.value = ‘Name’}”.
What this code says is that if onfocus (when you click on the textbox) the value attribute = Name then it gets overwritten with an empty string. If onblur (when you click out of the textbox) the value = the empty string it gets over written with Name but if the user has typed something before they clicked out of the box nothing happens and the text stays as they typed it.
This is how I used it.
If you want to see a working site where I used this go here
I’m not sure what other fields this can be used on I presume any that a user can type something into. I guess it could be used for password as well.
I hope this helps.
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.