473,800 Members | 2,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding onBlur/onFocus action to ALL elements?

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[i].elements.lengt h; j++){
el = document.forms[i].elements[j]
el.onFocus = fldBGChange;
el.onBlur = fldBGChange();
}
}
}

function fldBGChange(){
bgClr = this.style.back groundColor;
if(bgClr == fldBlurBG || bgClr == '' || bgClr == null){
this.style.back groundColor = 'yellow';
} else {
this.style.back groundColor = 'white';
}
}

Now, the idea is that when a user focuses on a field, it turns the
background yellow. However, this doesn't actually happen. Is there any
way to normalize the onFocus and onBlur events as opposed to adding
them to each field? Thanks for your help!

May 18 '06 #1
3 2310
VK

Nebulus wrote:
el.onFocus = fldBGChange;
el.onBlur = fldBGChange();


Event handlers (unlike HTML attributes) are case-sensitive and must be
in lowcase. You assign to event handler a function reference, not a
result of a function execution - thus no parenthesis.

el.onfocus = fldBGChange;
el.onblur = fldBGChange;

May 18 '06 #2
ASM
Nebulus a écrit :
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[i].elements.lengt h; j++){
el = document.forms[i].elements[j]
el.onFocus = function(){fldB GChange(this);}
el.onBlur = function(){fldB GChange(this);} }
}
}

function fldBGChange(){
function fldBGChange(wha t){
bgClr = what.style.back groundColor;
etc
Is there any
way to normalize the onFocus and onBlur events as opposed to adding
them to each field? Thanks for your help!


et pourquoi pas des CSS normales ?

or perhaps normal CSS won't work with IE Windows ?

<style type="text/css">
input { background: #ffc; color blue;}
input:hover { background: #ddd; color: maroon;}
input:focus { background: yellow; border: 3px solid red; color: red; }
</style>

the hover could not work with IE but does it with a lot of other browsers

--
Stephane Moriaux et son [moins] vieux Mac
May 18 '06 #3
I actually found the problem. I was using onFocus and onBlur instead of
the case correct: onfocus and onblur. It works perfectly now.

May 19 '06 #4

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

Similar topics

1
16606
by: Barry Svee | last post by:
I'm struggling with the JavaScript blur event. I have an activex control that I need to interact with when a window loses focus, namely to instruct it to give up control of a barcode scanner so that the application being brought foreward can take control. It has been my observation that when I set the window.onblur function, the window will gain focus and then immediately lose focus (blur) to the first field, button, or whatever that is...
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
10502
by: Tzachi | last post by:
Hello all, I have a function that dynamically adds rows and columns to the page. Everything works well except onfocus // onblur attributes. For some reason, when entering the input box it doesn't highlight. If I delete the onblur line, each of the boxes is highlighted all the time regardless of focusing the input box. Can someone help me?
2
1826
by: hrpreet | last post by:
Hi All, I have few textfields and dropdowns in my jsp, form is submitted on clicking an image link. In case there is an error for instance some text field is left empty, then message is displayed below respective fields ( using spans, inner html). The message is displayed onblur event of the field. So if there was an error then message is displayed, now if the user corrects the error and clicks the link then first the message...
2
10058
by: Robert Bravery | last post by:
HI all, I have a form for searches on a mysql database/table. The form has on input text box, and several pushbuttons. Depending on which pushbutton is selected, the search is then done on a specific field. One of them isa date field. How can I add or change the onfocus, onblur events of the input box to one that is relevant to the type of search being done. For example, I have some date format and valadation function, I would like to...
1
1934
by: clemtig | last post by:
Say I have a form with two input textfields. Each has an onFocus and onBlur. onFocus will unhide image #1. onBlur will hide image #1, show image #2 and validate the textfield. But the problem is that I get errors when going from one field to another with this combination. I've got it down to the point where I know that going from input field 1: onBlur --to-- input field 2: onBlur + onFocus
2
11669
by: Mathias Fritsch | last post by:
I try to run the following code, but no onblur/onfocus events happen. Is onfocus/onblur implemented in ie/firefox? <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <form> <TABLE BORDER="1" onFocus="alert('This is the Example Table')"
2
1433
by: laredotornado | last post by:
Hi, What handler would I set on a particular DIV if a user mouses out of that DIV or clicks outside of that DIV? Thanks, - Dave
1
2611
by: Duncan | last post by:
Hi all, I'm tearing my hair out on this! I have a simple ASP.NET 2 page with a TextBox control, in the PreRender I set ClientSide events:- Response.Attributes.Add("onchange", "javascript:alert('Changed');"); Response.Attributes.Add("onfocus",
0
9691
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
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
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
10035
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...
1
7580
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
6813
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
5471
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
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.