Partage
  • Partager sur Facebook
  • Partager sur Twitter

Validateur du W3C:erreurs dans un script

le script ne passe pas le validateur ...

Sujet résolu
    22 décembre 2005 à 22:37:29

    Bonjour à tous, :p

    Voilà, j'ai un petit souçi de validation pour un script trouvé sur le net. Comme je suis un grosse burne en JavaScript (si si n'ayons pas peur des mots ! ^^ ), j'en appelle à votre aide.

    Le script en question :
    <!-- DEBUT DU SCRIPT -->
    <script type="text/javascript">
    size=74;
    x = 3*size;
    place = 0;
    texte = 'blablabla exemple de texte blablabla';
    texteDef = texte;
    function defil()
            {
            texteDef = texteDef.substring(1,texteDef.length);
            while(texteDef.length < x)
                    {
                    texteDef += " - " + texte;
                    }
            document.defil.defilbox.value = texteDef;
            tempo2 = setTimeout("defil()", 130)
            }
    window.onload = defil;
    </script>
    <!-- FIN DU SCRIPT -->

    avec sa partie xHTML :
    <!--L'éditeur JavaScript : http://www.editeurjavascript.com/-->
    <form name="defil" id="defiletexte">
    <script type="text/javascript">
    document.write('<input type="text" name="defilbox" size=' + size + ' />');
    </script>
    </form>
    <!-- fin du script -->

    et la partie css :
    input
    {
         background-color:transparent;
         border-color:transparent;
         color:white;
         font-family:"Trebuchet ms", serif;
         font-size:1.0em;
    }
    #defiletexte
    {

    position:relative;
    display:block;
    width:460px;
    color:white;
    font-family:"Trebuchet ms", serif;
    font-size:0.8em;
    top:1px;
    left:165px;
    margin:0px;padding:0px;
    }


    Et voilà ce que me dit le validateur lorsque je passe ma page :

    Citation : validateur du w3c

    This page is not Valid XHTML 1.0 Strict!

    Below are the results of checking this document for XML well-formedness and validity.

    1. Warning Line 19 column 23: character "<" is the first character of a delimiter but occurred as data.

    while(texteDef.length < x)

    This message may appear in several cases:
    * You tried to include the "<" character in your page: you should escape it as "&lt;"
    * You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
    * Another possibility is that you forgot to close quotes in a previous tag.

    &#9993;
    2. Error Line 67 column 11: there is no attribute "name".

    <form name="defil" id="defile">

    You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

    This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

    How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute.

    &#9993;
    3. Error Line 67 column 30: required attribute "action" not specified.

    <form name="defil" id="defile">

    The attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.

    Typical values for type are type="text/css" for <style> and type="text/javascript" for <script>.

    &#9993;
    4. Error Line 69 column 68: document type does not allow element "input" here.

    ...put type="text" name="defilbox" size=' + size + '>');

    The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

    One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).


    J'aimerais donc rendre tout ça valide.

    Merci d'avance pour votre aide ! :);)
    • Partager sur Facebook
    • Partager sur Twitter
      22 décembre 2005 à 23:16:21

      Bon, chuis naze en JS aussi, mais bon, en suivant à la lettre les recommendations faites par le validateur, ça ne fonctionne pas ?
      Comme le < du script à transformer en &lt;, en rajoutant l'attribut action au formulaire, et encadrer le champ de texte par un paragraphe, même si cette zone de texte est générée par du JS ?
      • Partager sur Facebook
      • Partager sur Twitter
        22 décembre 2005 à 23:30:13

        Pour corriger l'erreur 1, je viens d'essayer de remplacer le < par &lt; mais ça ne marche pas : le script ne fonctionne plus ! :(

        Pour l'erreur 3, je ne sais pas quoi mettre pour action ...
        • Partager sur Facebook
        • Partager sur Twitter
          22 décembre 2005 à 23:38:02

          Pour la zone de texte, entourer par un paragraphe fonctionne ?
          Sinon, une solution de rechange, tu utilise un fichier .js, ça devrait fonctionner.
          Pour l'action.. Essaye de mettre un attribut action vide, voir si le script fonctionne toujours ?
          Et le name, j'imagine que l'attribut n'est pas correct sur un <form>, essaye de l'enlever ?
          • Partager sur Facebook
          • Partager sur Twitter
            22 décembre 2005 à 23:38:32

            Salut Pandore, pour l' erreur 1, tu peux essayer d' échapper le < par
            un anti slash , ou , si ça peut s' adapter , le transformer en <= .
            pour l' erreur 3 , je mettrais "#", pour action.
            Par contre pour name , tu ne peux pas l' enlever ,là je ne vois pas .
            ++

            Edit :
            Salut @lyric, il a besoin du name du form dans le script ,je vois
            toujours pas comment faire .
            • Partager sur Facebook
            • Partager sur Twitter
              22 décembre 2005 à 23:43:14

              Oups, j'ai oublié un bout de phrase.
              Il n'est pas possible de modifier l'attribut name par un attribut id, puis de rafistoler le code ?
              • Partager sur Facebook
              • Partager sur Twitter
                22 décembre 2005 à 23:43:49

                salut

                vite fait en passant, je rappelle que dans un formulaire, il faut mettre les éléments de type inline tels que input dans une balise de type block, exemple <p><input type="text" name="exemple" /></p>

                ++
                • Partager sur Facebook
                • Partager sur Twitter
                  22 décembre 2005 à 23:46:21

                  Pour la zone de texte, je ne vois pas bien où il faut mettre des balises paragraphes !? o_O

                  Sinon pour l'erreur 1, j'ai essayé de mettre un <= à la place du < mais ça me met toujours la même erreur. Et si je fait <\ à la place de <, le script ne fonctionne plus ... :(

                  Pour name, si je l'enlève, ça ne fonctionne plus non plus ... :(

                  Pour l'erreur 3 radecav, j'ai pas compris ta solution : je mets quoi exactement ???


                  Edit :
                  j'ai fait :
                  <!--L'éditeur JavaScript : http://www.editeurjavascript.com/-->
                  <form name="defil" id="defile">
                  <script type="text/javascript">
                  document.write('<p><input type="text" name="defilbox" size=' + size + ' /></p>');
                  </script>
                  </form>

                  et cj'ai une nouvelle erreur :

                  Citation : validateur du w3C

                  # Error Line 69 column 18: document type does not allow element "p" here.

                  document.write('<p><input type="text" name="defilbox" size=' + size + ' /></p>..

                  The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

                  One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

                  • Partager sur Facebook
                  • Partager sur Twitter
                    22 décembre 2005 à 23:52:51

                    Pour les balises de paragraphe , c' est comme dit scaler, sinon pour échapper
                    le < , il faut écrire : \<
                    Pour le form c' est <form name="defil" id ="defiltexte" action="#">
                    • Partager sur Facebook
                    • Partager sur Twitter
                      22 décembre 2005 à 23:55:00

                      <form action="#">
                      J'ai proposé un action vide plus haut, mais quant à savoir si ça fonctionne toujours...
                      Pour le paragraphe, tu devrais remplacer une ligne par celle-ci :

                      document.write('<p><input type="text" name="defilbox" size=' + size + ' /></p>');

                      Ca devrait marcher.

                      Edit : Oups, 3 minutes dans les dents.
                      • Partager sur Facebook
                      • Partager sur Twitter
                        22 décembre 2005 à 23:55:22

                        yop,

                        je n'y connais rien en JS, mais plutôt que de passer par l'attribut name, pourquoi ne pas plutôt sélectioner l'id, ainsi :

                        <!-- DEBUT DU SCRIPT -->
                        <script type="text/javascript">
                        size=74;
                        x = 3*size;
                        place = 0;
                        texte = 'blablabla exemple de texte blablabla';
                        texteDef = texte;
                        function defil()
                                {
                                texteDef = texteDef.substring(1,texteDef.length);
                                while(texteDef.length < x)
                                        {
                                        texteDef += " - " + texte;
                                        }
                                var defiletexte = document.getElementById(defiletexte);
                                document.defiletexte.defilbox.value = texteDef;
                                tempo2 = setTimeout("defil()", 130)
                                }
                        window.onload = defil;
                        </script>
                        <!-- FIN DU SCRIPT -->


                        J'ai juste changé defil par l'attribut id => defiletexte

                        Je sais même pas si ça peut marcher :p
                        En tout cas pour l'attribut action, si tu restes dans la même page, tu fais action="<?php echo $_SERVER['PHP_SELF']; ?>

                        bon courage.

                        pS: ouaip action vide c'est pas mal aussi :p... pas l'habitude de travailler avec le JS

                        EDIT : On en est où au niveau des erreurs ?
                        • Partager sur Facebook
                        • Partager sur Twitter
                          23 décembre 2005 à 0:01:38

                          Bon, ça avance les enfants lol : action="#" est bon ! :D

                          J'ai maintenant ça :

                          Citation : validateur du w3c

                          This page is not Valid XHTML 1.0 Strict!

                          Below are the results of checking this document for XML well-formedness and validity.

                          1. Warning Line 19 column 23: character "<" is the first character of a delimiter but occurred as data.

                          while(texteDef.length < x)

                          This message may appear in several cases:
                          * You tried to include the "<" character in your page: you should escape it as "&lt;"
                          * You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
                          * Another possibility is that you forgot to close quotes in a previous tag.

                          &#9993;
                          2. Error Line 67 column 11: there is no attribute "name".

                          <form name="defil" id="defile" action="#">

                          You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

                          This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

                          How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute.

                          &#9993;
                          3. Error Line 69 column 18: document type does not allow element "p" here.

                          document.write('<p><input type="text" name="defilbox" size=' + size + ' /></p>..

                          The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

                          One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).


                          • Partager sur Facebook
                          • Partager sur Twitter
                            23 décembre 2005 à 0:03:25

                            Oups, pour l'erreur 3 j'ai fait une boulette :p
                            Pour l'erreur 1 y'a la solution de ratdecav.
                            Edit : Et pour l'erreur 2 celle de scaler ?
                            • Partager sur Facebook
                            • Partager sur Twitter
                              23 décembre 2005 à 0:05:47

                              et si tu mettais plutôt :

                              <form action="#" id="defiletexte">
                                 <div>
                              <script type="text/javascript">
                              document.write('<input type="text" name="defilbox" size=' + size + ' />');
                                 </div>
                              </script>
                              </form>
                              • Partager sur Facebook
                              • Partager sur Twitter
                                23 décembre 2005 à 0:10:26

                                Non, ça ne marche pas ...

                                Si je fait \< au lieu de <, le script ne marche plus et si j'enléve le name="defil", le script ne marche plus non plus :'(


                                Note : le point 1 est un warning, ce n'est donc pas une erreur, à la limite, ça peut rester comme ça ;)
                                • Partager sur Facebook
                                • Partager sur Twitter
                                  23 décembre 2005 à 0:15:21

                                  http://www.la-grange.net/w3c/html4.01/interact/forms.html#adef-name-FORM

                                  c'est bizarre ce truc avec name... peux être devrais tu lire un peu les recommandations pour voir

                                  bonne nuit :p
                                  • Partager sur Facebook
                                  • Partager sur Twitter
                                    23 décembre 2005 à 0:18:15

                                    Sinon, essaye de supprimer le name et de mettre ça pour le JavaScript :

                                    <script type="text/javascript">
                                    size=74;
                                    x = 3*size;
                                    place = 0;
                                    texte = 'blablabla exemple de texte blablabla';
                                    texteDef = texte;
                                    function defil()
                                            {
                                            texteDef = texteDef.substring(1,texteDef.length);
                                            while(texteDef.length < x)
                                                    {
                                                    texteDef += " - " + texte;
                                                    }
                                            document.getElementById("defiletexte").value = texteDef;
                                            tempo2 = setTimeout("defil()", 130)
                                            }
                                    window.onload = defil;
                                    </script>
                                    • Partager sur Facebook
                                    • Partager sur Twitter
                                      23 décembre 2005 à 0:24:16

                                      J' ai du neuf :
                                      il faut supprimer les name et laisser les id que tu récupère comme çà :

                                      document.forms['defiltexte'].elements['defilbox'].value=textDef

                                      ou ( c' est moins sur) :

                                      document.forms['defiltexte'].defilbox.value=textDef


                                      où 'defitexte' et 'defilbox' sont les id de form et text bien sur .

                                      EDIT :
                                      Pour le < :
                                      essaye :

                                       ( x>texteDef.length )
                                      • Partager sur Facebook
                                      • Partager sur Twitter
                                        23 décembre 2005 à 0:29:14

                                        Ta solution ne marche pas @Lyric :(

                                        Sinon radelab, j'ai rien compris lol :lol:

                                        Je fais quoi exactement s.t.p. ???



                                        Edit :

                                        pour le <, c'est bon : ça marche ! il reste plus que ça :

                                        Citation : validateur du w3c

                                        # Error Line 67 column 11: there is no attribute "name".

                                        <form name="defil" id="defile" action="#">

                                        You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

                                        This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

                                        How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute.

                                        &#9993;
                                        # Error Line 69 column 70: document type does not allow element "input" here.

                                        ...type="text" name="defilbox" size=' + size + ' />');

                                        The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

                                        One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).


                                        :)
                                        • Partager sur Facebook
                                        • Partager sur Twitter
                                          23 décembre 2005 à 0:36:05

                                          Essaye :

                                          <!-- DEBUT DU SCRIPT -->
                                          <script type="text/javascript">
                                          size=74;
                                          x = 3*size;
                                          place = 0;
                                          texte = 'blablabla exemple de texte blablabla';
                                          texteDef = texte;
                                          function defil()
                                                  {
                                                  texteDef = texteDef.substring(1,texteDef.length);
                                                  while(x>texteDef.length)
                                                          {
                                                          texteDef += " - " + texte;
                                                          }
                                                  document.forms['defiletexte'].elements['defilbox'].value = texteDef;
                                                  tempo2 = setTimeout("defil()", 130)
                                                  }
                                          window.onload = defil();
                                          </script>
                                          <!-- FIN DU SCRIPT -->

                                          et

                                          <form  id="defiletexte">
                                          <script type="text/javascript">
                                          document.write('<input type="text" id="defilbox" size=' + size + ' />');
                                          </script>
                                          </form>
                                          • Partager sur Facebook
                                          • Partager sur Twitter
                                            23 décembre 2005 à 0:38:57

                                            nan, si je fais ça, le script ne fonctionne plus ... :(
                                            • Partager sur Facebook
                                            • Partager sur Twitter
                                              23 décembre 2005 à 0:42:58

                                              c' est cette ligne :
                                              peut être

                                              document.forms['defiletexte'].defilbox.value=textDef

                                              • Partager sur Facebook
                                              • Partager sur Twitter
                                                23 décembre 2005 à 0:48:17

                                                nan, pareil : si je fais ça, le script ne fonctionne plus ...
                                                • Partager sur Facebook
                                                • Partager sur Twitter
                                                  23 décembre 2005 à 0:57:35

                                                  J' ai fait une petite erreur :
                                                  j' ai écris :
                                                  window.onload = defil();

                                                  il faut mettre
                                                  window.onload = defil;
                                                  • Partager sur Facebook
                                                  • Partager sur Twitter
                                                    23 décembre 2005 à 1:05:43

                                                    ça a l'air de marcher car maintenant, j'ai plus qu'un seule erreur :D :

                                                    Citation : validateur du w3c

                                                    This page is not Valid XHTML 1.0 Strict!

                                                    Below are the results of checking this document for XML well-formedness and validity.

                                                    1. Error Line 68 column 68: document type does not allow element "input" here.

                                                    ...put type="text" id="defilbox" size=' + size + ' />');

                                                    The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

                                                    One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).


                                                    par contre, le hic, c'est que j'ai perdu en cours de route la mise en forme : la barre défilante était centrée (voir le css) et maintenant elle est alignée à gauche et elle est plus longue qu'avant ... o_O
                                                    • Partager sur Facebook
                                                    • Partager sur Twitter
                                                      23 décembre 2005 à 1:18:08

                                                      Pour le css , il y a pas de raison , j' ai fait un essai de couleur :
                                                      ça roule ( vérifie les termes ).
                                                      Pour la dernière erreur , essaie de mettre un <p></p> mais à l' extérieur du script :

                                                      <form  id="defiletexte">
                                                      <p>
                                                      <script type="text/javascript">
                                                      document.write('<input type="text" id="defilbox" size=' + size + ' />');
                                                      </script>
                                                      </p>
                                                      </form>


                                                      • Partager sur Facebook
                                                      • Partager sur Twitter
                                                        23 décembre 2005 à 1:26:29

                                                        nan, c'est pareil : j'ai toujours la même erreur :(

                                                        j'ai essayé aussi de mettre la balise "p" juste aprés celle de "script" mais il me dit que c'est pas le bon endroit ...
                                                        • Partager sur Facebook
                                                        • Partager sur Twitter
                                                          23 décembre 2005 à 1:31:17

                                                          Et si tu fais l' inverse :
                                                          <form  id="defiletexte">
                                                           
                                                           <input type="text" id="defilbox" size="javascript:document.write( size );">
                                                           
                                                          </form>
                                                          • Partager sur Facebook
                                                          • Partager sur Twitter
                                                            23 décembre 2005 à 1:41:06

                                                            Pas tout à fait mais en faisant :

                                                            <form  id="defiletexte" action="#">
                                                            <p>
                                                             <input type="text" id="defilbox" size="javascript:document.write( size );" />
                                                            </p>
                                                            </form>

                                                            ça marche !!! : le voyant passe au vert lol :D:p

                                                            par contre cette fois-ci, la barre de texte a vachement diminuée !!! o_O

                                                            je regarderais ça demain (car il se fait tard maintenant) et je te tiens au courant :)

                                                            merci beaucoup pour ton aide et ton obstination radecav. A demain pour la suite et bonne nuit à toi, tu l'as bien mérité ;)
                                                            • Partager sur Facebook
                                                            • Partager sur Twitter
                                                              23 décembre 2005 à 1:42:50

                                                              Bonne nuit, et bonne nuit aux chiens !!
                                                              a+
                                                              • Partager sur Facebook
                                                              • Partager sur Twitter

                                                              Validateur du W3C:erreurs dans un script

                                                              × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                                                              × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                                                              • Editeur
                                                              • Markdown