Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / January 2005



Tip: Looking for answers? Try searching our database.

Clearing a textbox in a function call

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
threepins@gmail.com - 30 Jan 2005 11:18 GMT
Howdy,

Just wondering how the following might be done:

I have a couple of different webpages that need to call a function to
clear the textbox onFocus of the textbox. I'm wanting to use one
function that I can call from a javascript include file (rather than
having multiple versions of the function all through the site).

So far i've tried the following:

function clearfield(poForm,poElement)
{
if (document.forms[poForm].poElement.value == "Type Search Here...")
document.forms[poForm].poElement.value = "";
}

where the passing page calls the function as:

clearfield('formname','formelement');

but just get errors.
Any help on this one would be most appreciative!!

Cheers
Bj McGowan
Dietmar Meier - 30 Jan 2005 12:40 GMT
> I have a couple of different webpages that need to call a function to
> clear the textbox onFocus of the textbox.

whatever.js:

function clrTxt(oElem, oEvent) {
 if (
   oElem
   && oElem.value
   && oElem.defaultValue
   && oEvent
   && oEvent.type
 ) {
   if (
     oEvent.type == "focus"
     && oElem.value == oElem.defaultValue
   ) {
     oElem.value = "";
   }
   else if (
     oEvent.type == "blur"
     && oElem.value == ""
   ) {
     oElem.value = oElem.defaultValue;
   }
 }
}

whatever.html:

...
<script type="text/javascript" src="whatever.js"></script>
...
<input ...
      onfocus="clrTxt(this, event)"
      onblur="clrTxt(this, event)"
      value="Type Search Here..."

...

ciao, dhgm    
Bj - 31 Jan 2005 06:32 GMT
Thanks Dietmar,

Worked a treat!

Bj

> > I have a couple of different webpages that need to call a function to
> > clear the textbox onFocus of the textbox.
[quoted text clipped - 37 lines]
>
> ciao, dhgm
Dietmar Meier - 31 Jan 2005 11:23 GMT
> Worked a treat!

Not really. Didn't test it before posting, and as I see now,
there's a mistake:

>> function clrTxt(oElem, oEvent) {
>>   if (
[quoted text clipped - 4 lines]
>>     && oEvent.type
>>   ) {

should, of course, be replaced with:

function clrTxt(oElem, oEvent) {
 if (
   oElem
   && typeof oElem.value != "undefined"
   && oElem.defaultValue
   && oEvent
   && oEvent.type
 ) {

ciao, dhgm
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.