ASP Hosting sale!
Double disk space and transfer for FREE!
Limited time offer! Act Now!

aspdev | articles | tutorials | forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Javascript form question

 
Post new topic   Reply to topic    ASPdev.org Forum Index -> JavaScript / DHTML / HTML / CSS
View previous topic :: View next topic  
Author Message
James



Joined: 20 Feb 2006
Posts: 24

PostPosted: Tue Mar 07, 2006 4:49 pm    Post subject: Javascript form question Reply with quote

In a form, I'd like to specify a value in the texbox, so that the value shows up in the text box before the user writes in it.

This is hard to explain, so hopefully you understand what i mean.

For example - The textbox might exist for the person to answer a question in.
As a default value, I'll put "Answer here" in the textbox.

When the user clicks the textbox I want that "answer here" text to disappear.
How do I achieve that?
Back to top
View user's profile Send private message
jon



Joined: 01 Oct 2004
Posts: 40

PostPosted: Tue Mar 07, 2006 9:02 pm    Post subject: Reply with quote

Well, something like that should work:

<form name="Form1">

<input type="text" name="Question" value="Answer here" onclick="this.form.Question.value=''">

</form>

I haven't tested this code but it should work as it is.



Jon
Back to top
View user's profile Send private message
jon



Joined: 01 Oct 2004
Posts: 40

PostPosted: Thu Mar 09, 2006 12:08 pm    Post subject: Reply with quote

Hi James,

Did my code work for you?




Jon
Back to top
View user's profile Send private message
rose



Joined: 21 Feb 2006
Posts: 29

PostPosted: Thu Mar 16, 2006 6:40 pm    Post subject: Reply with quote

Go to howstuffworks.com
Their search bar at the top uses this feature.

You can view the code in the source of that page, its simple javascript.

Its something like this:

Code:
<input type="text" class="searchText" onblur="if(this.value=='') {this.value='text123';}"
                    onfocus="if(this.value=='Search HowStuffWorks and the Web') {this.value='';}" size="33" maxlength="50" name="search" value="text123">
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ASPdev.org Forum Index -> JavaScript / DHTML / HTML / CSS All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group

SQL Tutorial