Javascript

Fermé
yann5 Messages postés 398 Date d'inscription lundi 24 mars 2008 Statut Membre Dernière intervention 1 mai 2015 - 9 mars 2010 à 21:10
yann5 Messages postés 398 Date d'inscription lundi 24 mars 2008 Statut Membre Dernière intervention 1 mai 2015 - 9 mars 2010 à 22:01
Bonjour,


j'aimerais faire une gallerie d'images simple donc j'ai fais ce code :

<head>
<script language="JavaScript">
window.onload = "var photo='1'";

function verifPhoto(action) {

if (action==suiv) {photo++;}
if (action==prec) {photo--;}

switch (photo) {

case '1':
document.getElementByName(photo).src ='http://wakstep.u7n.org/include/img/minis/frederic.JPG';
document.getElementByName(photo).alt = 'Frédéric';
break;

default:
document.getElementsByName(photo).src = 'http://wakstep.u7n.org/include/img/noimage.gif';
document.getElementByName(photo).alt = 'Fin de liste';
break;

}
if (photo<='0') {photo='1';}
if (photo>='2') {photo='1';} // photo = dernière photo (num)
}

</script>
</HEAD>
<BODY OnLoad="var photo='1'">
<table align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" colspan="2" height="22"><center>
<img name="photo" src="http://wakstep.u7n.org/include/img/minis/frederic.JPG" alt="Frédéric" />
</center>
</td>
</tr>
<tr>
<td width="50%" nowrap><p align="left"><a href="JAVASCRIPT:" onClick="verifPhoto('prec')"><font size='3' color='red'>Image Précédente</font></a></td>
<td width="50%" nowrap><p align="right"><a href="JAVASCRIPT:" onClick="verifPhoto('suiv')"><font size='3' color='red'>Image Suivante</font></a></td>
</tr>
</table>
</body>


Mais quand je fais image précédente ou image suivante on devrait m'afficher http://wakstep.u7n.org/include/img/noimage.gif mais rien.

2 réponses

Zestyr Messages postés 466 Date d'inscription mercredi 12 août 2009 Statut Membre Dernière intervention 17 octobre 2011 52
9 mars 2010 à 21:36
Salut en regardant ton code j'ai pu apercevoir 2 grosse fautes:

if (action==suiv) {photo++;} 
if (action==prec) {photo--;} 

---> if (action=="suiv") {photo++;}
               if (action=="prec") {photo--;}  // ce sont des strings

var photo='1' ---> var photo = 1 // c'est un entier !
0
yann5 Messages postés 398 Date d'inscription lundi 24 mars 2008 Statut Membre Dernière intervention 1 mai 2015 61
9 mars 2010 à 22:01
merci mais ca ne marche toujours pas
0