473,403 Members | 2,071 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,403 software developers and data experts.

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

function fldBGChange(){
bgClr = this.style.backgroundColor;
if(bgClr == fldBlurBG || bgClr == '' || bgClr == null){
this.style.backgroundColor = 'yellow';
} else {
this.style.backgroundColor = '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 2286
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.length; j++){
el = document.forms[i].elements[j]
el.onFocus = function(){fldBGChange(this);}
el.onBlur = function(){fldBGChange(this);} }
}
}

function fldBGChange(){
function fldBGChange(what){
bgClr = what.style.backgroundColor;
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
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...
1
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...
1
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...
2
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...
2
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...
1
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...
2
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>...
2
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
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",...
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: 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
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,...
0
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...
0
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...
0
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,...
0
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...

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.