Hello,
I found this simple js star rating script that I want to modify slightly.
firstly I want to retain current vote , say 3 stars, untill its changed again.
right now it resets to unvoted on refresh. I know you could use cookies but
I also want to give it a unique identifier so that if i put it in my topic header templet, its unique to each topic (retaining whatever vote for each topic untill changed again) .
perhaps this is not possible without a database. I have no access to my hosts server.
I found this simple js star rating script that I want to modify slightly.
firstly I want to retain current vote , say 3 stars, untill its changed again.
right now it resets to unvoted on refresh. I know you could use cookies but
I also want to give it a unique identifier so that if i put it in my topic header templet, its unique to each topic (retaining whatever vote for each topic untill changed again) .
perhaps this is not possible without a database. I have no access to my hosts server.
Code:
<script type="text/javascript">
<!--
var set=false;
var v=0;
var a;
function loadStars()
{
star1 = new Image();
star1.src = "http://www.ednasia.com/images/unratedStar.gif";
star2 = new Image();
star2.src= "http://www.geekpedia.com/Samples/Rate/star2.gif";
}
function highlight(x)
{
if (set==false)
{
y=x*1+1
switch(x)
{
case "1": document.getElementById(x).src= star2.src;
document.getElementById('vote').innerHTML="one star";
break;
case "2":for (i=1;i<y;i++)
{
document.getElementById(i).src= star2.src;
}
document.getElementById('vote').innerHTML="two stars"
break;
case "3":for (i=1;i<y;i++)
{
document.getElementById(i).src= star2.src;
}
document.getElementById('vote').innerHTML="three stars"
break;
case "4":for (i=1;i<y;i++)
{
document.getElementById(i).src= star2.src;
}
document.getElementById('vote').innerHTML="four stars"
break;
case "5":for (i=1;i<y;i++)
{
document.getElementById(i).src= star2.src;
}
document.getElementById('vote').innerHTML="five stars"
break;
}
}
}
function losehighlight(x)
{
if (set==false)
{
for (i=1;i<6;i++)
{
document.getElementById(i).src=star1.src;
document.getElementById('vote').innerHTML=""
}
}
}
function setStar(x)
{
y=x*1+1
if (set==false)
{
switch(x)
{
case "1": a="1"
flash(a);
break;
case "2": a="2"
flash(a);
break;
case "3": a="3"
flash(a);
break;
case "4":a="4"
flash(a);
break;
case "5":a="5"
flash(a);
break;
}
set=true;
document.getElementById('vote').innerHTML="Thank you for your vote!"
}
}
function flash()
{
y=a*1+1
switch(v)
{
case 0:
for (i=1;i<y;i++)
{
document.getElementById(i).src= star1.src;
}
v=1
setTimeout(flash,200)
break;
case 1:
for (i=1;i<y;i++)
{
document.getElementById(i).src= star2.src;
}
v=2
setTimeout(flash,200)
break;
case 2:
for (i=1;i<y;i++)
{
document.getElementById(i).src= star1.src;
}
v=3
setTimeout(flash,200)
break;
case 3:
for (i=1;i<y;i++)
{
document.getElementById(i).src= star2.src;
}
v=4
setTimeout(flash,200)
break;
case 4:
for (i=1;i<y;i++)
{
document.getElementById(i).src= star1.src;
}
v=5
setTimeout(flash,200)
break;
case 5:
for (i=1;i<y;i++)
{
document.getElementById(i).src= star2.src;
}
v=6
setTimeout(flash,200)
break;
}
}
loadStars()
-->
</script>
<img src="star1.gif" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="1" style="width:30px; height:30px; float:left;" />
<img src="star1.gif" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="2" style="width:30px; height:30px; float:left;" />
<img src="star1.gif" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="3" style="width:30px; height:30px; float:left;" />
<img src="star1.gif" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="4" style="width:30px; height:30px; float:left;" />
<img src="star1.gif" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="5" style="width:30px; height:30px; float:left;" /><br /><br />
<div id="vote" style="font-family:tahoma; color:red;"></div>
Comment