Mettre script de notes plusieurs fois

Résolu
Alexandre67 Messages postés 80 Statut Membre -  
Alexandre67 Messages postés 80 Statut Membre -
Bonjour,

voici mon problème, j'ai un script de note que j'ai trouvé sur un site mais il ne marche que une fois par page et le problème c'est que j'ai besoin d'une note pour chaque nouveau message posté alors bon .. si quelqu'un pourrait m'aider sachant que je m'y connais presque pas en JS ce serait sympa :)


Le JS entre <head> et </head>

<script type="text/javascript">
<!--
var set=false;
var v=0;
var a;
function loadStars()
{
star1 = new Image();
star1.src = "star1.gif";
star2 = new Image();
star2.src= "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;
}
}
-->
</script>


Le HTML :

<body onload="loadStars()">

<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>

....



Merci à vous d'avance !

2 réponses

Ozimandias Messages postés 528 Statut Membre 46
 
Ta page est une page html ou php?

Tu peux commencer en mettant tes fonctions java dans un fichier .js que tu appelle dans chaque page ce qui allègera la lecture de ton code...
Si tu nommes ton fichier toto.js tu peux procéder comme suit, à placer dans le HEAD:

<script language="javascript" type="text/javascript" src="adresse/toto.js"></script>


0
Alexandre67 Messages postés 80 Statut Membre 3
 
Ok merci pour l'astuce ! Je mets en résolue car j'ai résolue mon problème :)
0