473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Clearing a textbox in a function call

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

Jul 23 '05 #1
3 6049
th*******@gmail.com 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
Jul 23 '05 #2
Bj
Thanks Dietmar,

Worked a treat!

Bj

"Dietmar Meier" <us***************@innoline-systemtechnik.de> wrote in
message news:36*************@individual.net...
th*******@gmail.com 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

Jul 23 '05 #3
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
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RelaxoRy | last post by:
If I fill out the textfields properly with Name, Email etc in a row it is fine. But if I fill out, for example, my Name, then tab twice, it clears my entered value. How do I stop this? All I...
2
by: anonieko | last post by:
This applies to javascript dynamic textbox onkey > > > Newsgroups: comp.lang.javascript From: Lasse Reichstein Nielsen <l...@hotpop.com> - Find messages by this author Date: Fri, 15 Jul 2005...
2
by: Savvas | last post by:
Hi everybody, I have a lot of textboxes on my form and a "Clear" button. Is there a way with a for loop or something to clear the textboxes, instead of writing textboxName.clear? Thanks a lot
4
by: Ali | last post by:
I used to clear my page's control in Visual Studio 2003 using code like this: Dim c As Control For Each c In Page.Controls(1).Controls If TypeOf c Is TextBox Then CType(c, TextBox).Text = Nothing...
9
by: Michael.Suarez | last post by:
foreach (TextBox tb in this.Controls) tb.Dispose(); What this does is clears every other textbox on the form. Suppose there are 10 textboxes... this will dispose the 1st one, then i guess...
1
by: RLN | last post by:
Re: Access 2003 I found a method here in the newsgroup that works for clearing checkboxes, but don't understand a particular line of code and how it works. Here is the code: 1. Dim ctrl As...
0
by: asumal | last post by:
Hello I am new to ASP.NET. I am using CreateUserWizard control to register & create a user. I am using Membership API. I have a Cancel button on the CreateUserWizard step 2 alongwith Create User ...
2
by: thisismykindabyte | last post by:
Hey-o! Can anyone tell me how to make this work? Long story short, I would like to use text from TextBox1.Text as the functions I would like to call. Then I would like TextBox1.Text to show...
4
by: fosterb | last post by:
I am a c# developer struggling with an ASP.NET problem and I have no web development experience at all, so I suspect that my question will be an easy one to the right person. I am trying to fix a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.