Home   News  Product reviews  Website reviews  Forums   Competitions  Subscribe 
Seen This Blog


Web Building >> Web design & build
 |  Print Topic
Jump to first unread post. Pages: 1
lezbfranz
new user


Reg'd: Fri
Posts: 2
clear textbox
      #163341 - Fri Feb 18 2005 06:57 PM

I am new to this forum and asp. I did read a earlier thread which helped me ---I want to clear a textbox when the user clicks on it--I am putting a default value in it but if they want to enter a value I want the textbox to clear when they click it. The solution I saw in this forum was:
<html>
<head>
<script language="javascript">
function cleartext()
{
document.form1.textbox.value = ""
}
</script>
</head>
<body>
<form name="form1">
<input type="text" value="Enter Keywords here..." onclick="cleartext()">
</form>
</body>
</html>

When I use this and run it --and then click on a textbox field I get a message at the bottom of the browser "error on page". Now this script is running in iis. I also tried changing the script to VBscript. Does anyone know why I am getting this error??

THANKS!


Post Extras: Print Post   Remind Me!   Notify Moderator  
NanookModerator
regular


Reg'd: Tue
Posts: 995
Loc: South East England
Re: clear textbox [Re: lezbfranz]
      #163370 - Fri Feb 18 2005 08:24 PM

Don't know why you are getting the error but you can use this code instead:

<form name="form1">
<input type="text" value="Enter Keywords here..." onFocus="value=''">
</form>

To see an example of this see www.bains007.co.uk (my site; it's on the Google search box)


Post Extras: Print Post   Remind Me!   Notify Moderator  
lezbfranz
new user


Reg'd: Fri
Posts: 2
Re: clear textbox [Re: Nanook]
      #163461 - Fri Feb 18 2005 11:11 PM

THANKS! That worked---not quite like I want but it will do! I really appreciate the help!!

SMILES!



Post Extras: Print Post   Remind Me!   Notify Moderator  
NanookModerator
regular


Reg'd: Tue
Posts: 995
Loc: South East England
Re: clear textbox [Re: lezbfranz]
      #163463 - Fri Feb 18 2005 11:11 PM

No probs, what was it you wanted to do?

http://www.bains007.co.uk


Post Extras: Print Post   Remind Me!   Notify Moderator  
slapmatt
regular


Reg'd: Mon
Posts: 509
Loc: Wiltshire
Re: clear textbox [Re: Nanook]
      #164381 - Mon Feb 21 2005 11:25 AM

nanook - the problem with your code is that it clears the text box EVERY time the user clicks on it.

My code will only clear the text box if the text in the box is the same as your default text.

<html>
<head>
<title>
</title>
<script>
function clearText()
{
if (document.myForm.keyword.value == document.myForm.defaultText.value)
{
document.myForm.keyword.value = "" ;
}
}
</script>
</head>
<body align="center">
<form name="myForm">
<input type="text" name="keyword" value="Enter keyword here..." onClick="JavaScript: clearText()">
<input type="hidden" name="defaultText" value="Enter keyword here...">
</form>
</body>
</html>


Post Extras: Print Post   Remind Me!   Notify Moderator  
NanookModerator
regular


Reg'd: Tue
Posts: 995
Loc: South East England
Re: clear textbox [Re: slapmatt]
      #164455 - Mon Feb 21 2005 03:53 PM

Sorry, hadn't quite read the script correctly, don't know how to do what you want, search Google and there are lots of results

http://www.bains007.co.uk


Post Extras: Print Post   Remind Me!   Notify Moderator  
Matt
regular


Reg'd: Wed
Posts: 92
Loc: England
Re: clear textbox [Re: slapmatt]
      #165105 - Wed Feb 23 2005 01:05 PM

Tried that code, but it doesn't seem to like existing forms, with different names.




Post Extras: Print Post   Remind Me!   Notify Moderator  
slapmatt
regular


Reg'd: Mon
Posts: 509
Loc: Wiltshire
Re: clear textbox [Re: Matt]
      #165119 - Wed Feb 23 2005 02:20 PM

Change the names then!


Post Extras: Print Post   Remind Me!   Notify Moderator  
Matt
regular


Reg'd: Wed
Posts: 92
Loc: England
Re: clear textbox [Re: slapmatt]
      #165125 - Wed Feb 23 2005 02:40 PM

I've changed the names in the bit in <head> section of code, but it still doesn't work. I can't change my forms' names to MyForm either, as there are two different forms on one page, with different names.


Post Extras: Print Post   Remind Me!   Notify Moderator  
slapmatt
regular


Reg'd: Mon
Posts: 509
Loc: Wiltshire
Re: clear textbox [Re: Matt]
      #165352 - Thu Feb 24 2005 08:32 AM

OK, try this badboy.

<html>
<head>
<title>
</title>
<script>
function clearText(textElement, defaultElement)
{
if (textElement.value == defaultElement.value)
{
textElement.value = "" ;
}
}
</script>
</head>
<body align="center">
<form name="myForm">
<input type="text" name="keyword" value="Enter keyword here..." onClick="JavaScript: clearText(this, document.myForm.defaultText);">
<input type="hidden" name="defaultText" value="Enter keyword here...">
</form>
</body>
</html>

The only think you'll need to change is the document.myForm.defaultText so that it points to the hidden element in your form that holds the default text.

Therefore, if your form name is MattsForm and the hidden element in the form that holds the default text is called MattsDefaultText you'll need to change the line to:

document.MattsForm.MattsDefaultText


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1

Rate this topic

Jump to


Extra information
0 registered and 2 anonymous users are browsing this forum.

Moderator:  putasolutions, Joe_London, greysts, bricat, Nanook, Hello_There, John_McKenna, Mouse, TheFatControlleR 


Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      Mark-up is enabled

Rating:
Topic views: 1693

Contact Us | Privacy statement Main website