Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Clearing a textbox in a function call

Reply
Thread Tools

Clearing a textbox in a function call

 
 
threepins@gmail.com
Guest
Posts: n/a
 
      01-30-2005
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

 
Reply With Quote
 
 
 
 
Dietmar Meier
Guest
Posts: n/a
 
      01-30-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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
 
Reply With Quote
 
 
 
 
Bj
Guest
Posts: n/a
 
      01-31-2005
Thanks Dietmar,

Worked a treat!

Bj

"Dietmar Meier" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> (E-Mail Removed) wrote:
>
> > 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



 
Reply With Quote
 
Dietmar Meier
Guest
Posts: n/a
 
      01-31-2005
Bj wrote:

> 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 (
>> oElem
>> && oElem.value
>> && oElem.defaultValue
>> && oEvent
>> && 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call function whose function call with arguments is in astring Options grbgooglefan C Programming 4 01-30-2008 05:12 PM
How to call function whose function call with arguments is in astring grbgooglefan C++ 2 01-30-2008 07:18 AM
Clearing an ASP textbox on click LeSam ASP .Net Web Controls 1 04-06-2005 05:51 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
clearing a textbox and filling with a function RelaxoRy Javascript 2 04-19-2004 05:27 PM



Advertisments