Quote:
Originally Posted by KkillgasmM
I have a script that will loop through each input and textarea field on a page and set onfocus and onblur events to change the background colour.
Here is some of the code that does it
Code:
elementInput[j].onfocus = active;
elementInput[j].onblur = deActive;
elementInput[j].onload = deActive;
Here are the functions that are called to do this:
Code:
// makes a text field turn white on hover
function active ()
{
var field = document.getElementById (this.id);
field.style.backgroundColor="#FFF";
}
// makes a text field turn light grey on blur
function deActive ()
{
var field = document.getElementById (this.id);
field.style.backgroundColor="#F9F9F9";
}
However, the
Code:
elementInput[j].onload = deActive;
Part of the code does not work. It doesnt create an error, but it just doesn't do anything! Its supposed to make all the input fields turn grey using the deActive function, but nothing seems to happen?
|
My understanding is that the onload event is only valid on certain elements, such as body, img, and iframe (i.e., elements that need to be loaded). I don't think onload would work on an input field.
If you are trying to make the default background-color of that element to be a certain color, then it is better to set it in the CSS than JavaScript.
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
|