Tech Support Forum banner
Status
Not open for further replies.
1 - 4 of 4 Posts

· Registered
Joined
·
28 Posts
Discussion Starter · #1 ·
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 :)
 

· Registered
Joined
·
2,300 Posts
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
 

· Registered
Joined
·
2,300 Posts
Thats k =]

Glad to help,
Jamey
 
1 - 4 of 4 Posts
Status
Not open for further replies.
Top