/    Sign up×
Community /Pin to ProfileBookmark

mouseover change images

Hi people,

I’ve put together a piece of javascript to change images… But I am a complete idiot when it comes to JavaScript, so off course it didn’t work :p

What I’m trying to do: I’m working with a rating system on my site. I want to reproduce the same idea that is used on entertainment.msn.com (at the photographs). There are 5 stars there, that display the current rating. But when you mouse over a star, for example the 3rd, the first 3 stars become yellow, the other 2 gray.

This is the code that doesn’t work:

<script language=”JavaScript”>

// Preload Stars ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
img_star_sel = new Image();
img_star_sel.src = “http://www.rijkvanwel.nl/e107/e107_images/rate/msn/6.gif“;
img_star_on = new Image();
img_star_on.src = “http://www.rijkvanwel.nl/e107/e107_images/rate/msn/5.gif“;
img_star_off = new Image();
img_star_off.src = “http://www.rijkvanwel.nl/e107/e107_images/rate/msn/1.gif“;

function starsel(rate,over)
{// Calculate number of stars ::::::::::::::::::::::::::::::::::::::::::::::
var stars_on = rate;
var stars_off = 5 – rate;

// Mouse over / mouse out :::::::::::::::::::::::::::::::::::::::::::::::::
if (over = TRUE)
{// Change Images ::::::::::::::::::::::::::::::::::::::::::::::::::::::
document.star_1.src = img_star_sel.src;
if (stars_on > 1)
{document.star_2.src = img_star_sel.src;}
else
{document.star_2.src = img_star_off.src;}
if (stars_on > 2)
{document.star_3.src = img_star_sel.src;}
else
{document.star_3.src = img_star_off.src;}
if (stars_on > 3)
{document.star_4.src = img_star_sel.src;}
else
{document.star_4.src = img_star_off.src;}
if (stars_on > 4)
{document.star_5.src = img_star_sel.src;}
else
{document.star_5.src = img_star_off.src;}
}
else
{// Change Images ::::::::::::::::::::::::::::::::::::::::::::::::::::::
document.star_1.src = img_star_on.src;
if (stars_on >= 1,5)
{document.star_2.src = img_star_on.src;}
else
{document.star_2.src = img_star_off.src;}
if (stars_on >= 2,5)
{document.star_3.src = img_star_on.src;}
else
{document.star_3.src = img_star_off.src;}
if (stars_on >= 3,5)
{document.star_4.src = img_star_on.src;}
else
{document.star_4.src = img_star_off.src;}
if (stars_on >= 4,5)
{document.star_5.src = img_star_on.src;}
else
{document.star_5.src = img_star_off.src;}
}

}

</script>

Could someone please help me out here? Thanks in advance!!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@pj59Dec 28.2004 — Hello!

Provided that your html is okay (including the correct function calls on mouseover and out) you will have to edit this line:

if (over [COLOR=red]= TRUE[/COLOR])

Javascript is case sensitive and [COLOR=red]= TRUE[/COLOR] has to be [COLOR=blue]== true[/COLOR]. Even better would be to simply leave it out:

if(over)

would be enough.

Regards PJ
Copy linkTweet thisAlerts:
@RidgeauthorDec 28.2004 — Thank you very much for the quick reply! I've changed the script and it works properly now. Thanks again!
Copy linkTweet thisAlerts:
@pj59Dec 28.2004 — Hi! You're welcome! ?

PJ
×

Success!

Help @Ridge spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...