473,796 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(poFo rm,poElement)
{
if (document.forms[poForm].poElement.valu e == "Type Search Here...")
document.forms[poForm].poElement.valu e = "";
}

where the passing page calls the function as:

clearfield('for mname','formele ment');

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

Cheers
Bj McGowan

Jul 23 '05 #1
3 6067
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.defaultVa lue
&& oEvent
&& oEvent.type
) {
if (
oEvent.type == "focus"
&& oElem.value == oElem.defaultVa lue
) {
oElem.value = "";
}
else if (
oEvent.type == "blur"
&& oElem.value == ""
) {
oElem.value = oElem.defaultVa lue;
}
}
}

whatever.html:

....
<script type="text/javascript" src="whatever.j s"></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.d e> wrote in
message news:36******** *****@individua l.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.defaultVa lue
&& oEvent
&& oEvent.type
) {
if (
oEvent.type == "focus"
&& oElem.value == oElem.defaultVa lue
) {
oElem.value = "";
}
else if (
oEvent.type == "blur"
&& oElem.value == ""
) {
oElem.value = oElem.defaultVa lue;
}
}
}

whatever.html:

...
<script type="text/javascript" src="whatever.j s"></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.defaultVa lue
&& oEvent
&& oEvent.type
) {


should, of course, be replaced with:

function clrTxt(oElem, oEvent) {
if (
oElem
&& typeof oElem.value != "undefined"
&& oElem.defaultVa lue
&& 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
1822
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 want the script to do is that when the cell is blank or whitespace, put the necessary text in the field, else, continue as normal. --- HTML Extract
2
13728
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 18:39:24 +0200 Local: Fri,Jul 15 2005 12:39 pm Subject: Re: Summer 2005 browsers' test set ?
2
1871
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
4429
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 End If If TypeOf c Is DropDownList Then CType(c, DropDownList).SelectedIndex = 0 End If Next
9
2198
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 whatever list of textboxes it's maintaining gets shifted, so the 2nd is now the 1st in the list, so when it goes to the next one, it is destroying the 3rd textbox, leaving the 2nd one safe...
1
2579
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 Control 2. For Each ctrl In Me.Controls 3. 'uncheck all of the checkboxes...
0
1380
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 button & Previous button. Actually, i have added some more textboxes on the default control for taking user's personal information. The problem is that when i call the below mentioned code all textboxes for user's personal information gets cleared...
2
1103
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 the result of the functions I just called. (Pretend the line below is a textbox) So therefore, TextBox1.Text would look like this = "Multiply(4,GrabNumFromAray(RandomNumGen(4)))"
4
1287
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 bug whereby a licence number is not being cleared from a web page. The user clicks an "Add" button on a web page, gets directed to a new page, enters their licence number which is made up of 5 text boxes in a line, submits the page and goes back to...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.