Remplacer Name par ID (javascript)

Résolu/Fermé
Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009 - 1 juin 2008 à 13:15
RAD ZONE Messages postés 5226 Date d'inscription samedi 20 janvier 2007 Statut Contributeur Dernière intervention 1 juin 2024 - 1 juin 2008 à 17:04
Bonjour,

voice ma page internet reduite:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type" />
<title>Untitled 1</title>

<script language="javascript" type="text/javascript">

Image1 = new Image(265,406)
Image1.src = "http://www.lou-castelet.fr/project/pic/langbar.png"

Image2 = new Image(265,406)
Image2.src = "http://www.lou-castelet.fr/project/pic/ukover.png"

Image3 = new Image(265,406)
Image3.src = "http://www.lou-castelet.fr/project/pic/frover.png"

Image4 = new Image(265,406)
Image4.src = "http://www.lou-castelet.fr/project/pic/nlover.png"

function fr() {
document.emp.src = Image3.src; return true;
}

function uk() {
document.emp.src = Image2.src; return true;
}

function nl() {
document.emp.src = Image4.src; return true;
}

function original() {
document.emp.src = Image1.src; return true;
}
</script> 
</head>

<body>

<img alt="langbar" name="emp" src="http://www.lou-castelet.fr/project/pic/langbar.png" usemap="#ep" />
<map name="ep">
<area alt="francais" coords="122, 43, 25" href="../"  onmouseout="original()" onmouseover="fr()" shape="circle" />
<area alt="nederlands" coords="189, 43, 25" href="/home_nl.html" onmouseout="original()" onmouseover="nl()" shape="circle" />
<area alt="English" coords="54, 43, 25" href="/home_uk" onmouseout="original()" onmouseover="uk()" shape="circle" />
<area alt="noselect" nohref="nohref" shape="default" />
</map>
</body>

</html>


Vous voyez cette ligne:
<img alt="langbar" name="emp" src="http://www.lou-castelet.fr/project/pic/langbar.png" usemap="#ep" />


il y a un "name". Recement j'ai essayé de faire valider ma page pour xhtml 1.0 strict et le validateur m'a indiquer qu'il faut utiliser ID au lieu de Name.
Pouvez vous m'aider a adapter mon code javascript pourqu'il marche avec id="langbar" dans l'image

Merci d'avance

5 réponses

RAD ZONE Messages postés 5226 Date d'inscription samedi 20 janvier 2007 Statut Contributeur Dernière intervention 1 juin 2024 1 355
1 juin 2008 à 14:12
un truc dans ce style
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
  <head>    
    <meta content="text/html; charset=windows-1252" http-equiv="Content-Type" />    
    <title>Untitled 1     
    </title>
<script language="javascript" type="text/javascript">
Image1 = new Image(265,406)
Image1.src = "http://www.lou-castelet.fr/project/pic/langbar.png"
Image2 = new Image(265,406)
Image2.src = "http://www.lou-castelet.fr/project/pic/ukover.png"
Image3 = new Image(265,406)
Image3.src = "http://www.lou-castelet.fr/project/pic/frover.png"
Image4 = new Image(265,406)
Image4.src = "http://www.lou-castelet.fr/project/pic/nlover.png"
function fr(id){
img = document.getElementById(id).src = Image3.src; return true;
}
function uk(id){
img = document.getElementById(id).src = Image2.src; return true;
}
function nl(id){
img = document.getElementById(id).src = Image4.src; return true;
}
function original(id){
img = document.getElementById(id).src = Image1.src; return true;
}
</script>    
  </head>  
  <body>    
   <img alt="langbar" id="emp" src="http://www.lou-castelet.fr/project/pic/langbar.png" usemap="#ep" />
    <map name="ep">
      <area alt="francais" coords="122, 43, 25" href="../"  onmouseout="original('emp')" onmouseover="fr('emp')" shape="circle" />
      <area alt="nederlands" coords="189, 43, 25" href="/home_nl.html" onmouseout="original('emp')" onmouseover="nl('emp')" shape="circle" />
      <area alt="English" coords="54, 43, 25" href="/home_uk" onmouseout="original('emp')" onmouseover="uk('emp')" shape="circle" />
      <area alt="noselect" nohref="nohref" shape="default" />
    </map>  
  </body>
</html>
1
Brachior Messages postés 613 Date d'inscription dimanche 21 octobre 2007 Statut Membre Dernière intervention 22 juin 2009 46
1 juin 2008 à 13:26
j'pense que ca devrait le faire :
function fr(id){
img = document.getElementById(id).src ... }

et dans tes bouton :
<area alt="francais" coords="122, 43, 25" href="../" onmouseout="original()" onmouseover="fr('emp')" shape="circle" />
0
Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009
1 juin 2008 à 13:48
je comprens pas buen comment faire le lien avec les images plus haut...

peut tu m'expliquer mieux ou reecrire une parite du code comme exemple?

Merci beaucoup :)
0
RAD ZONE Messages postés 5226 Date d'inscription samedi 20 janvier 2007 Statut Contributeur Dernière intervention 1 juin 2024 1 355
1 juin 2008 à 13:26
????

tu met id a la place de name !!
<img alt="langbar" id="emp" src="http://www.lou-castelet.fr/project/pic/langbar.png" usemap="#ep" />    
    <map id="ep">      
      <area alt="francais" coords="122, 43, 25" href="../"  onmouseout="original()" onmouseover="fr()" shape="circle" />      
      <area alt="nederlands" coords="189, 43, 25" href="/home_nl.html" onmouseout="original()" onmouseover="nl()" shape="circle" />      
      <area alt="English" coords="54, 43, 25" href="/home_uk" onmouseout="original()" onmouseover="uk()" shape="circle" />      
      <area alt="noselect" nohref="nohref" shape="default" />    
    </map>  
  </body>

0
Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009
1 juin 2008 à 13:47
rad zone, tu n'a rien compris a ma question. Si je fais ca mon script js ne marche plus.
0
RAD ZONE Messages postés 5226 Date d'inscription samedi 20 janvier 2007 Statut Contributeur Dernière intervention 1 juin 2024 1 355
1 juin 2008 à 13:48
pardon ???

il faut bien sur passer en
document.getElementById


0
Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009
1 juin 2008 à 14:03
oui mais comment j'ecris ca? pouvez vous donner le script complet avec les liens et tout car je suis complettement perdu et je m'y connaias pas en js
0
Brachior Messages postés 613 Date d'inscription dimanche 21 octobre 2007 Statut Membre Dernière intervention 22 juin 2009 46 > Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009
1 juin 2008 à 14:06
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type" />
<title>Untitled 1</title>

<script language="javascript" type="text/javascript">

Image1 = new Image(265,406)
Image1.src = "http://www.lou-castelet.fr/project/pic/langbar.png"

Image2 = new Image(265,406)
Image2.src = "http://www.lou-castelet.fr/project/pic/ukover.png"

Image3 = new Image(265,406)
Image3.src = "http://www.lou-castelet.fr/project/pic/frover.png"

Image4 = new Image(265,406)
Image4.src = "http://www.lou-castelet.fr/project/pic/nlover.png"

function fr(id) {
document.getElementById(id).src = Image3.src; return true;}

function uk(id) {
document.getElementById(id).src = Image2.src; return true;}

function nl(id) {
document.getElementById(id).src = Image4.src; return true;}

function original(id) {
document.getElementById(id).src = Image1.src; return true;}
</script> 
</head>

<body>

<img alt="langbar" id="emp" src="http://www.lou-castelet.fr/project/pic/langbar.png" usemap="#ep" />
<map name="ep">
<area alt="francais" coords="122, 43, 25" href="../"  onmouseout="original('emp')" onmouseover="fr('emp')" shape="circle" />
<area alt="nederlands" coords="189, 43, 25" href="/home_nl.html" onmouseout="original('emp')" onmouseover="nl('emp')" shape="circle" />
<area alt="English" coords="54, 43, 25" href="/home_uk" onmouseout="original('emp')" onmouseover="uk('emp')" shape="circle" />
<area alt="noselect" nohref="nohref" shape="default" />
</map>
</body>

</html>
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
RAD ZONE Messages postés 5226 Date d'inscription samedi 20 janvier 2007 Statut Contributeur Dernière intervention 1 juin 2024 1 355
1 juin 2008 à 14:16
looool si tu as pas compris apres ca !!

2 pour le prix d un ;-))
0
Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009
1 juin 2008 à 14:39
ouais! merci les gars vous etes les meilleurs!

pour le resultat: http://lou-castelet.fr/project

J'ai quand meme une derniere question :p
comment remplacer "name" par "id" dans le <map> ??

allez ici: http://validator.w3.org/check?uri=http%3A%2F%2Fwww.lou-castelet.fr%2Fproject%2F
pour voir ce que je veux dire

Merci encore :)
0
Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009 > Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009
1 juin 2008 à 14:46
ah j'ai resolu le probleme!

j'ai mis n'importe quel ID et ca marche!
0
Brachior Messages postés 613 Date d'inscription dimanche 21 octobre 2007 Statut Membre Dernière intervention 22 juin 2009 46 > Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009
1 juin 2008 à 14:50
oui il faut mettre name ET id pr valider ^^
0
Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009 > Brachior Messages postés 613 Date d'inscription dimanche 21 octobre 2007 Statut Membre Dernière intervention 22 juin 2009
1 juin 2008 à 14:51
ouais merci, c'est ce que j'avais fait
0
Brachior Messages postés 613 Date d'inscription dimanche 21 octobre 2007 Statut Membre Dernière intervention 22 juin 2009 46 > Winterboard Messages postés 137 Date d'inscription jeudi 8 mai 2008 Statut Membre Dernière intervention 30 juin 2009
1 juin 2008 à 16:51
cloture la discussion si tu as resolu ton prob ;)
0