473,788 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Capture onFocus event

Hi Friends...
I have an query on how to capture onFocus event for all the input
controls without writing onFocus event in the <input> tag.

say my html form has 3 or 4 or 5 input text boxes, now I want to
capture onFocus event for all the text boxes without writing onFocus
code in <input> tag.

for example:
<form name="frm1">
<input type="text" name="t1">
<input type="text" name="t2">
<input type="text" name="t3">
</form>

now in above example whenever user shifts the focus to input 1 i.e. t1
box, then some action should be taken say alert message is displayed,
then when focus shifts to input 2 i.e. t2 box, then same action is
displayed & alert message is displayed. for this I dont want to write
code given below:

<form name="frm1">
<input type="text" name="t1" onFocus="alert( 'hi')">
<input type="text" name="t2" onFocus="alert( 'hi')">
<input type="text" name="t3" onFocus="alert( 'hi')">
</form>

If some body could help me.....

Thanks in Advance

Regards
Paresh Shah
Jul 23 '05 #1
2 3140
Paresh Shah wrote:
Hi Friends...
I have an query on how to capture onFocus event for all the input
controls without writing onFocus event in the <input> tag.


var inputs = frm1.getElement sByTagname('inp ut');
for(var i=0; i < inputs.length; i++) b
inputs[i].onfocus = function {
alert('hi');
}
}

or

var inputs = frm1.getElement sByTagname('inp ut');
inputs[0].prototype.onfo cus = function {
alert('hi');
}
I didn't test those, and I might be a bot off with the syntax, but this is
the direction to look at.

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 23 '05 #2
On Tue, 4 May 2004 13:11:16 +0200, Berislav Lopac
<be************ @dimedia.hr> wrote:

[snip]
var inputs = frm1.getElement sByTagname('inp ut');
var inputs = form.getElement sByTagName( 'INPUT' );
for(var i=0; i < inputs.length; i++) b
for( var i = 0, n = inputs.length; i < n; ++i ) {
inputs[i].onfocus = function {
alert('hi');
}
It would be best to use a single function and assign its reference, rather
than create an anonymous function for each element.
}

or

var inputs = frm1.getElement sByTagname('inp ut');
As above.
inputs[0].prototype.onfo cus = function {
I don't know how successful that will be. Some browsers may not provide a
prototype for the element. The single function argument above applies
here, too.
alert('hi');
}

I didn't test those, and I might be a bot off with the syntax, but this
is the direction to look at.


It's a shame that IE is such a pile of crap. If it supported event
capturing (as introduced in DOM 2 Events), this would be so much easier.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #3

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

Similar topics

4
2402
by: Scott Navarre | last post by:
Hi, I have Red Hat 8.0 and have the default Mozilla browser that comes with it. I am programming in javascript and have come across something problematic. Given the following code: <HTML> <HEAD> </HEAD> <BODY> <FORM>
1
20277
by: Rich Morey | last post by:
Hello, I have created a form and assigned each of the form elements to a class in a style sheet. I would like to know if it is possible to add 'OnFocus' and 'OnBlur' events to the style sheet class so that I can change the background color of a form element WITHOUT having to add 'OnFocus' and 'OnBlur' events to each individual form element..
1
8766
by: Michael Albanese | last post by:
I am developing an application to handle my compay's OSHA reporting requirements. Some of the input criteria are technical and narowly defined, so I was trying to prvide what i call "Context Sensitive Help" by providing a short instructional message based on which control has Focus. Because of the way that a Radio Button List control is rendered in the browser i can not attach an onFocus event
2
3988
by: swathi | last post by:
----------------------------------------------------------------------- A poll associated with this post was created, to vote and see th results, please visit http://www.forum4designers.com/message103437.htm ----------------------------------------------------------------------- Question: iframe onfocus problem in mozilla browse - attached zip fil - multi.html in attached zi...
1
2388
by: Eric Trav | last post by:
Hello, I am using mozilla and javascript to change the style background color for my select with onfocus() and back to white with onblur(). When i process onfocus(); i have to click on the select three times to get the popup menu and everything seems slow. No errors are reported in the console however it seems as if the click event is not being processed after the focus event is processed.
5
19175
by: Max | last post by:
I've got a default value of some text in an input element when a page loads. What I'd like to do is have the value disappear when the user clicks in the input field. I've figured out I can use: onclick="this.value='';" This works fine, however if for some reason the user adds his own input, then click somewhere else/clicks back, the text has once again been erased.
3
2310
by: Nebulus | last post by:
Hey all. I'm working on some VERY big forms, and the user will easily lose their location if they get distracted - which happens a lot with the amount of phone traffic they get. Anyway, I have a function like this: function initForms(){ for(i = 0; i < document.forms.length; i++){ for(j = 0; j < document.forms.elements.length; j++){ el = document.forms.elements
2
2478
by: Jonathan N. Little | last post by:
As part of a JavaScript precheck form validation I noticed a problem with trying to return focus to the field with an error. I have setup a demo page. http://www.littleworksstudio.com/temp/usenet/focus.html To simulate the problem, just enter or change the "first" textbox and either click or tab to another control., it is tied to the onchange event. An alert box that simulates the "warning". When you close it the focus will not move...
2
4709
by: wolverine | last post by:
Hi All, In Mozilla Firefox, to onblur and onfocus event of each and every html element, the browser itself will attach a native event handler. I mean if you type, 'javascript:alert(window.blur)' in the address bar of Firefox browser, you can see a 'function ....' . That is a Firefox browser defined handler. Now assume that web developer also attach event handlers to 'onblur' events eg: 'window.blur=f3()'
0
9498
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
10177
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
10118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
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
6750
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();...
1
4074
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
3677
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.