Javascript function to change img src

Hi guys,
I’m trying to make the logo on a webpage to change when the user hovers over some brands in a dropdown menu. I created the function below in my javascript file.

function changelogobrand(brand) 
{
document.getElementById("logo").src="/data/image/logo"+ brand + ".png";
}

The links in the menu have onmouseover="changelogobrand(<php echo $brand; ?>” wich passes the brand name to the function. I use this in order to correctly load the brand logos wich are stored as “logoBrand.png” in /data/image folder on server.

The error I get in firebug console when I hover over the menu is “reference error: BMW is not defined” or “reference error: Mercedes is not defined” and so on depending on the brand I am hovering over.

What am I doing wrong?

robertot5 wrote:
> Hi guys,
> I’m trying to make the logo on a webpage to change when the user hovers
> over some brands in a dropdown menu.
>
> What am I doing wrong?

Easy. Using Javascript. Use CSS instead. Please don’t ask me to rant
about why Javascript is evil when CSS can do the job. :slight_smile:

I know CSS should be used, but I have to change the img src of another element in page, not the one I am hovering with, so I cannot use the element:hover in CSS.
Is it possible to change the img src of an element in page when hovering over a totally different element, all this with CSS3 ?

robertot5 wrote:
> djh-novell;2579174 Wrote:
>> robertot5 wrote:
>>> Hi guys,
>>> I’m trying to make the logo on a webpage to change when the user
>> hovers
>>> over some brands in a dropdown menu.
>>>
>>> What am I doing wrong?
>> Easy. Using Javascript. Use CSS instead. Please don’t ask me to rant
>> about why Javascript is evil when CSS can do the job. :slight_smile:
>
> I know CSS should be used, but I have to change the img src of another
> element in page, not the one I am hovering with, so I cannot use the
> element:hover in CSS.
> Is it possible to change the img src of an element in page when
> hovering over a totally different element, all this with CSS3 ?

Apparently, the answer is it might be:

http://stackoverflow.com/questions/4502633/how-to-affect-other-elements-when-a-div-is-hovered
http://stackoverflow.com/questions/1462360/css-hover-one-element-effect-for-multiple-elements
http://stackoverflow.com/questions/4559178/can-you-apply-a-css-hover-effect-to-an-element-thats-not-a-child-of-the-hovered
et al

Thanks, I’ll check those out!