# Form Field Onclick remove text re-appear upon delete



## aldernon

Im making a submit form for a friend and am having some trouble.

The form is made and works great. I have made it so when a user clicks on the field, the text in the box dissapears, love it.

HOWEVER, if a user clicks on the box, doesnt type anything then clicks away, then the original text remains gone and I fear the user may forget what the field is for.

My question is how I make it so the original field's text return if the user clicks on the box, types nothing, thus clearing the box's contents. Can this be done? So far the only way i can make the text re-appear is if i navigate away from then back to the page. Also, I dont really want to use a reset button as it affects the design.

Here is an example of a field I have made:
<input onfocus="this.select()" name="name" type="text" value="Name:"

<input onfocus="this.select()" name="email" type="text" value="E-mail:">

Here is the page:
http://www.musicamor.com/iu/index-7.html


Ive read about onblur and tried a few examples but cant seem to get it to work right. 

Thank you for reading, 
I appreciate your time


----------



## jamiemac2005

Hey =] i have an answer for you,
The onblur event handler is fine, but within it you have to check if there's anything typed in the box and if theres not re-enter it i've tried it like this(and it works):



Code:


<input onfocus="this.select()" [b]onblur="this.value=!this.value?'Seu Nome:':this.value;"[/b] name="name" value="Seu Nome:" type="text">

effectively what the line of code "this.value=!this.value?'Seu Nome':this.value;" does is:

Sets the value of the text box to either:
- (if theres something in the input box) it sets it to the text thats in the input box(leaving it alone)
- (if not) it sets it to the text between the two single quotes(')

If you need more info on it then post back but that code works so give it a go =]

Cheers,
Jamey


----------



## aldernon

As soon as I saw it your post, I knew it would work perfectly 

I've tried it, and its great!!! Thanks alot for your help, duno what I'd do without you 


Working exampe 
http://www.musicamor.com/iu/index-7.html


----------



## jamiemac2005

Thats k =]

Glad to help,
Jamey


----------

