Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-12-2013, 11:18 PM   PM User | #1
nerdydev
New to the CF scene

 
Join Date: Jun 2011
Posts: 9
Thanks: 5
Thanked 0 Times in 0 Posts
nerdydev is an unknown quantity at this point
text input hint value not clearing onclick

Having problems with a very simple script, I want the value of the text input to be cleared when the user clicks the box, but only if it is the default value, but it wont work.

This is the function:
Code:
function clear()
{
var text = document.getElementByName('s').value;

if(text == "Search Site...")
  {
  	document.getElementByName('s').value="";
  }
}
And this is the input:
Code:
<input type="text" size="9" name="s"  value="Search Site..." onclick="clear()"/>
Any ideas?

Thanks in advance.
nerdydev is offline   Reply With Quote
Old 02-12-2013, 11:23 PM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 961
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
You need to use the error console, which will tell you about a non-existent function.
Logic Ali is offline   Reply With Quote
Old 02-13-2013, 08:09 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
To auto-retore default text in a textbox:-

Code:
<input type = "text" name = "uname" id = "uname" value = "Name: "  onclick = "if (this.value == 'Name: ') this.value = '';"  onblur = "if (this.value == '') this.value = 'Name: ';" />
<br>

<input type = "text" name = "email" id = "email" value = "Email: "  onclick = "if (this.value == 'Email: ') this.value = '';"  onblur = "if (this.value == '') this.value = 'Email: ';" />


Expecting the world to treat you fairly because you are good is like expecting the bull not to charge because you are a vegetarian.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
nerdydev (02-13-2013)
Old 02-13-2013, 11:44 AM   PM User | #4
nerdydev
New to the CF scene

 
Join Date: Jun 2011
Posts: 9
Thanks: 5
Thanked 0 Times in 0 Posts
nerdydev is an unknown quantity at this point
thanks Philip M, was looking for a way to do it in-line, thank you.
nerdydev is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:52 AM.


Advertisement
Log in to turn off these ads.