Jump to content

Rating script won't work...


Vigilant Psyche

Recommended Posts

Hi.

 

I'm tyring to make a little script to highlight a series of stars up until where you hover (youtube style). But my script won't work:

 

	function rate_show(num)
{

	var i=0;

	for(i=0;i<num;i++)
	{
		document.GetElementById(i).src="images/rate.png";
	}

	var j=0;
	var not=5-num;

	for(j=0;j<not;j++)
	{
		document.GetElementById(j).src="images/rate_off.png";
	}
}

 

 

Anything obvious wrong?  ???

 

 

HTML is as follows:

 

<image src='images/rate_off.png' id='0' onmouseover='rate_show(0)'/> <image src='images/rate_off.png' id='1' onmouseover='rate_show(1)'/> <image src='images/rate_off.png' id='2' onmouseover='rate_show(2)'/> etc...

Link to comment
https://forums.phpfreaks.com/topic/116336-rating-script-wont-work/
Share on other sites

getElementById starts with a lowercase 'g'. Aside from that, the logic of your "not" part doesn't really work. You can do something like this:

<html>
<head>
<script language="JScript">
function rate_show(e)
{
	for(var i=0;i<=e.id;i++)
	{
		document.getElementById(i).src="images/rate.png";
		e.onmouseout=function()
		{
			e.src="images/rate_off.png";
		}
	}
}
</script>
</head>
<bodY>
<image src='images/rate_off.png' id='0' onmouseover="rate_show(this)"><image src='images/rate_off.png' id='1' onmouseover="rate_show(this)"><image src='images/rate_off.png' id='2' onmouseover="rate_show(this)"><image src='images/rate_off.png' id='3' onmouseover="rate_show(this)"><image src='images/rate_off.png' id='4' onmouseover="rate_show(this)">
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.