IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

pb javascript


Sujet :

JavaScript

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Points : 61
    Points
    61
    Par défaut pb javascript
    j'ai un fichier html qui se remplit avec les données d'un xml par l'intérmédiaire d'une fonction javascript.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
     
    <div style="text-align: left;"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
    <html xmlns="<a href="http://www.w3.org/1999/xhtml" target="_blank">http://www.w3.org/1999/xhtml</a>">
    <head>
    <title>Historique</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script language="JavaScript">
    AfficheDocXML();
    function AfficheDocXML()
    {
    var Document;
    Document = new ActiveXObject("Microsoft.XMLDOM");
    Document.async = "false";
    var couleur;
    if(Document.load("data.xml"))
    {
     document.write("<TABLE BORDER=1 CELLPADDING=0>");
     
     for(i=1;i<Document.documentElement.childNodes.length;i++)
     {
             document.write ("<TR ALIGN=center>");
                    for(j=0;j<= 7;j++)
      {
                     document.write ("<TD>");
       if (j != 6)
                     document.write (Document.documentElement.childNodes(i).childNodes(j).text);
     
       if (j == 6)
       {
       couleur = Document.documentElement.childNodes(i).childNodes(6).text;
       //alert(Document.documentElement.childNodes(i).childNodes(6).text);
       document.write (Document.documentElement.childNodes(i).childNodes(7).style.color = couleur);
       }
                             document.write ("</TD>");
                    }
                    document.write ("</TR>");
             }
    document.write ("</TABLE>"); 
    }
    else
    {alert("fichier pas trouvé !");}
    }        
    </script>
    </head>
    <body>
    </body>
    </html>
     </div>
    je voudrais que la couleur de l'element n°7

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Document.documentElement.childNodes(i).childNodes(7).style.color = couleur
    prendre une certaine couleur en fonction de sa valeur

    lorsque j'execute le script, j'ai l'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <div style="text-align: left;">documentElement.childNodes(...).childNodes(...).style a la valeur null ou n'est pas un objet</div>
    est ce que quelqu'un pourrait m'expliquer pourquoi???
    votre aide serait vraiment, vraiment, vraiment tres précieuse.

  2. #2
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 642
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 642
    Points : 66 668
    Points
    66 668
    Billets dans le blog
    1
    Par défaut
    tu n'aurais pas un problème d'instanciation ... ???
    tu lances la focntion alors que les objets ene sont pas encore créés ...
    lances ta fonction sur le onload du body ou après la balise de fermeture du body ...

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Points : 61
    Points
    61
    Par défaut
    comment ça apres la balise de fermeture?

    en fait j'ai séparé mon pb en 2 fonctions:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
    <html xmlns="<a href="http://www.w3.org/1999/xhtml" target="_blank">http://www.w3.org/1999/xhtml</a>">
    <head>
    <title>Historique</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script language="JavaScript">
    AfficheDocXML();
    function AfficheDocXML()
    {
    var Document;
    Document = new ActiveXObject("Microsoft.XMLDOM");
    Document.async = "false";
     
    if(Document.load("data.xml"))
    {
     document.write("<TABLE BORDER=1 CELLPADDING=0>");
     
     for(i=1;i<Document.documentElement.childNodes.length;i++)
     {
            document.write ("<TR ALIGN=center>");
            for(j=0;j<= 7;j++)
      {
                     document.write ("<TD>");
       if (j != 6)
                     document.write (Document.documentElement.childNodes(i).childNodes(j).text);
     
       if (j == 6)
       {
       //couleur = Document.documentElement.childNodes(i).childNodes(6).text;
       //alert(Document.documentElement.childNodes(i).childNodes(6).text);
       //document.write (Document.documentElement.childNodes(i).childNodes(7).style.color = couleur);
       }
                             document.write ("</TD>");
                    }
                    document.write ("</TR>");
             }
    document.write ("</TABLE>"); 
    }
    else
    {alert("fichier pas trouvé !");}
    }   
    function couleur()
    {
    var couleur;
     for(i=1;i<Document.documentElement.childNodes.length;i++)
     {
      for(j=0;j<= 7;j++)
      {
       if (j == 6)
       {
       couleur = Document.documentElement.childNodes(i).childNodes(6).text;
       document.write (Document.documentElement.childNodes(i).childNodes(7).style.color = couleur);
       alert(couleur);
       }
      }
     }
    }     
    </script>
    </head>
    <body>
    </body>
    </html>
    je ne vois pas comment faire appel à ma fnction couleur??

  4. #4
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 642
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 642
    Points : 66 668
    Points
    66 668
    Billets dans le blog
    1
    Par défaut
    réfléchis sur le déroulement ...
    quand tes objets sont ils instanciés et quand tes fonctions sont elles lancées ...

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Points : 61
    Points
    61
    Par défaut
    en fait je veux que mes objets se créent au fur et à mesure.
    et une fois que mes éléments existent, ils prennent la bonne couleur.


  6. #6
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 642
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 642
    Points : 66 668
    Points
    66 668
    Billets dans le blog
    1
    Par défaut
    et bien lance tout simplement ta fonction de coloration après la balise de fermeture du body ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    </body>
    <script type='text/javascript'>
    couleur()
    </script>
    ou encore dans le onload de la balise body ...

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Points : 61
    Points
    61
    Par défaut
    je commence à désespérer quelquesoit l'endroit ou je fais appel à ma fonction couleur ça ne change rien:

    mon fichier xml contient les données comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
     
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <Societe>
    <Entete>
    <Champ1>Date</Champ1>
    <Champ2>Heure</Champ2>
    <Champ3>Durée</Champ3>
    <Champ4>OF </Champ4>
    <Champ5>Phase </Champ5>
    <Champ6>Etat machine </Champ6>
    <Champ7>Couleur </Champ7>
    <Champ8>Opérateur</Champ8>
    </Entete>
    <Data>
    <Champ1>05/04/2006</Champ1>
    <Champ2>05:00:07</Champ2>
    <Champ3>339</Champ3>
    <Champ5>1003</Champ5>
    <Champ6>0020</Champ6>
    <Champ8>                </Champ8>
    <Champ4>#FFAA00</Champ4>
    <champ7>PAS DE PERSONNEL</champ7>
    </Data>
    <Data>
    <Champ1>05/04/2006</Champ1>
    <Champ2>05:05:46</Champ2>
    <Champ3>8</Champ3>
    <Champ5>1003</Champ5>
    <Champ6>0020</Champ6>
    <Champ8>VANUXEM CEDRIC  </Champ8>
    <Champ4>#FFAA00</Champ4>
    <champ7>PAS DE PERSONNEL</champ7>
    </Data>
    </Societe>
    et mon fichier html est definit comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
    <html xmlns="<a href="http://www.w3.org/1999/xhtml" target="_blank">http://www.w3.org/1999/xhtml</a>">
    <head>
    <title>Historique</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script language="JavaScript">
    AfficheDocXML();
    function AfficheDocXML()
    {
    var Document;
    Document = new ActiveXObject("Microsoft.XMLDOM");
    Document.async = "false";
     
    if(Document.load("data.xml"))
    {
     document.write("<TABLE BORDER=1 CELLPADDING=0>");
     
     for(i=1;i<Document.documentElement.childNodes.length;i++)
     {
            document.write ("<TR ALIGN=center>");
            for(j=0;j<= 7;j++)
      {
                document.write ("<TD>");
       if (j != 6) document.write (Document.documentElement.childNodes(i).childNodes(j).text);
       document.write ("</TD>");
            }
            document.write ("</TR>");
        }
    document.write ("</TABLE>"); 
    }
    else
    {alert("fichier pas trouvé !");}
    }   
    function couleur()
    {
    var coul;
     for(i=1;i<Document.documentElement.childNodes.length;i++)
     {
      for(j=0;j<= 7;j++)
      {
       if (j == 6)
       {
       coul = Document.documentElement.childNodes(i).childNodes(6).text;
       Document.documentElement.childNodes(i).childNodes(7).style.color = coul ;
       }
      }
     }
    }     
    </script>
    </head>
    <body onload="couleur()">
    </body>
    <script type='text/javascript'>
    //couleur()
    </script>
    </html>
    quand je lance mon fichier html nommé test.html, j'obtiens un tableau qui contient les données tel que:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    05/04/2006 05:00:07 33910030020                            PAS DE PERSONNEL
    05/04/2006 05:05:46 810030020     VANUXEM CEDRIC  PAS DE PERSONNEL
    05/04/2006 05:05:54 610030020                               PAS DE PERSONNEL
    05/04/2006 05:06:00 21410030020                            PRODUCTION
    05/04/2006 05:09:34 4210030020                              ARRET INDETERMINE
    05/04/2006 05:10:16 4710030020                              PRODUCTION
    05/04/2006 05:11:03 34110030020                            ARRET INDETERMINE
    05/04/2006 05:16:44 9310030020                              PRODUCTION
    05/04/2006 05:18:17 7210030020                              ARRET INDETERMINE
    seuelment les noms "PRODUCTION", "PAS DE PERSONNEL", etc n'ont pas la couleur que je veux..............

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Points : 61
    Points
    61
    Par défaut
    svp à l'aide

  9. #9
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 642
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 642
    Points : 66 668
    Points
    66 668
    Billets dans le blog
    1
    Par défaut
    tu es sous ie OU FIREFOX car la gestipon des chilNodes n'est pas la même ...

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Points : 61
    Points
    61
    Par défaut
    sous ie

  11. #11
    Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Points : 61
    Points
    61
    Par défaut
    y'a quelqu'un?????????????

  12. #12
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 642
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 642
    Points : 66 668
    Points
    66 668
    Billets dans le blog
    1
    Par défaut
    as tu testé en faisant un alert du innerHTML du node visé pour savoir si tu y accèdes

  13. #13
    Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Points : 61
    Points
    61
    Par défaut
    c'est bon j'ai fait autrement
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
    <html xmlns="<a href="http://www.w3.org/1999/xhtml" target="_blank">http://www.w3.org/1999/xhtml</a>">
    <head>
    <title>Historique</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script language="JavaScript">
    function AfficheDocXML()
    {
    var Document;
    Document = new ActiveXObject("Microsoft.XMLDOM");
    Document.async = "false";
    var coul = 'blue';
    if(Document.load("data.xml"))
    {
     document.write("Historique de la machine");
     document.write("<TABLE BORDER=0 CELLPADDING=0>");
     
     for(i=0;i<Document.documentElement.childNodes.length;i++)
     {
            document.write ("<TR ALIGN=center>");
            for(j=0;j<= 7;j++)
      {
      if (j < 5) {document.write ("<TD width='10%'>");}
      else if (j == 6) {document.write ("<TD width='0%'>");}
      else {document.write ("<TD width='30%'>");}
     
      if ((j != 6)&&(j!= 7)) 
       {document.write (Document.documentElement.childNodes(i).childNodes(j).text);}
     
     
     
       if (j ==6)
       {
        coul = Document.documentElement.childNodes(i).childNodes(6).text;
       }
       if ((j ==7)&&(i !=0))
       {
        switch (coul)
       {
        case '1': document.write ("<DIV style='color : #0000FF'>");document.write (Document.documentElement.childNodes(i).childNodes(j).text);document.write ("</DIV>");break;
        case '2': document.write ("<DIV style='color : #0055FF'>");document.write (Document.documentElement.childNodes(i).childNodes(j).text);document.write ("</DIV>");break;
        case '3': document.write ("<DIV style='color : #00FF00'>");document.write (Document.documentElement.childNodes(i).childNodes(j).text);document.write ("</DIV>");break;
        case '4': document.write ("<DIV style='color : #FF0000'>");document.write (Document.documentElement.childNodes(i).childNodes(j).text);document.write ("</DIV>");break;
        case '5': document.write ("<DIV style='color : #FF00FF'>");document.write (Document.documentElement.childNodes(i).childNodes(j).text);document.write ("</DIV>");break;
        case '6': document.write ("<DIV style='color : #111111'>");document.write (Document.documentElement.childNodes(i).childNodes(j).text);document.write ("</DIV>");break;
        case '7': document.write ("<DIV style='color : #111111'>");document.write (Document.documentElement.childNodes(i).childNodes(j).text);document.write ("</DIV>");break;
        case '8': document.write ("<DIV style='color : #0055FF'>");document.write (Document.documentElement.childNodes(i).childNodes(j).text);document.write ("</DIV>");break;
        case '9': document.write ("<DIV style='color : #FFAA00'>");document.write (Document.documentElement.childNodes(i).childNodes(j).text);document.write ("</DIV>");break;
       }
       }
       document.write ("</TD>");
            }
            document.write ("</TR>");
        }
    document.write ("</TABLE>"); 
    }
    else
    {alert("fichier pas trouvé !");}
    }   
    </script>
    </head>
    <body >
    </body>
    <script type='text/javascript'>
    AfficheDocXML()
    </script>
    </html>
    et ça marche nickel!!!!

  14. #14
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 642
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 642
    Points : 66 668
    Points
    66 668
    Billets dans le blog
    1
    Par défaut
    Juste à titre de precaution je te conseillerais de faire un truc du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    coul = Document.documentElement.childNodes(i).childNodes((document.all)?6:7;).text;
    juste pour etre compatible IE et FFX ...
    enfin fais le test tu verras bien ...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Les meilleurs livres pour apprendre le JavaScript
    Par vermine dans le forum Livres
    Réponses: 23
    Dernier message: 10/06/2019, 18h58
  2. JavaScript<---->ActionScript
    Par crazypiou dans le forum Flash
    Réponses: 21
    Dernier message: 17/04/2009, 17h14
  3. Construire chemin sur bouton avec évt Javascript
    Par Ph. B. dans le forum XMLRAD
    Réponses: 4
    Dernier message: 27/05/2003, 10h26
  4. appel xmlservice via fonction javascript
    Par pram dans le forum XMLRAD
    Réponses: 2
    Dernier message: 06/05/2003, 14h24
  5. JavaScript de vérification de formulaire
    Par [DreaMs] dans le forum XMLRAD
    Réponses: 6
    Dernier message: 26/02/2003, 13h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo