The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Remove default text from text area

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #29646


    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 … 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

    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.


    Hi there I fixed the problem. I didn’t use makeshift’s Jquery suggestion thank you though.

    The javascript source from … 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.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.