Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  1] [ 2]  / answers: 1 / hits: 24214  / 11 Years ago, fri, april 12, 2013, 12:00:00

I tried this code but its not working; when I on-focus textbox it shows an error:


function ChangeBgColor(obj, evt) 
{
if(evt.type=="focus")
style.background ="lightgrey";
else if(evt.type=="blur")
{
style.background="white";
}
}

More From » html

 Answers
32

What is style? You have not defined it anywhere in your code above:



function ChangeBgColor(obj, evt) 
{
if(evt.type==focus)
style.background =lightgrey; //<--what is style?
else if(evt.type==blur)
{
style.background=white;
}
}


I am guessing that you wanted something like



obj.style.background =lightgrey;


And in the code above, simplified



function ChangeBgColor(obj, evt) 
{
obj.style.background = (evt.type==focus) ? lightgrey : white;
}


The best answer is to use pure CSS.


[#78947] Thursday, April 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quinn

Total Points: 160
Total Questions: 86
Total Answers: 101

Location: Belarus
Member since Tue, Mar 14, 2023
1 Year ago
;