View previous topic :: View next topic |
Author |
Message |
James
Joined: 20 Feb 2006 Posts: 24
|
Posted: Tue Mar 07, 2006 4:49 pm Post subject: Javascript form question |
|
|
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 |
|
|
jon
Joined: 01 Oct 2004 Posts: 40
|
Posted: Tue Mar 07, 2006 9:02 pm Post subject: |
|
|
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 |
|
|
jon
Joined: 01 Oct 2004 Posts: 40
|
Posted: Thu Mar 09, 2006 12:08 pm Post subject: |
|
|
Hi James,
Did my code work for you?
Jon |
|
Back to top |
|
|
rose
Joined: 21 Feb 2006 Posts: 29
|
Posted: Thu Mar 16, 2006 6:40 pm Post subject: |
|
|
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 |
|
|
|
|
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
|