Remplacer Name par ID (javascript)

Résolu
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

  1. Contributeur
    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. 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" />
      1. 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 :)
    2. Contributeur
      ????

      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>

      1. rad zone, tu n'a rien compris a ma question. Si je fais ca mon script js ne marche plus.
    3. Contributeur
      pardon ???

      il faut bien sur passer en
      document.getElementById


      1. 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
      2. @Winterboard
        <!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>
    4. Contributeur
      looool si tu as pas compris apres ca !!

      2 pour le prix d un ;-))
      1. @Winterboardah j'ai resolu le probleme!

        j'ai mis n'importe quel ID et ca marche!
      2. @Brachiorouais merci, c'est ce que j'avais fait