Need your help to validate my page

Discussion in 'HTML & Website Design' started by nabil_kadimi, Apr 27, 2007.

  1. #1
    I'm triying to create an XHTML/transitional valid page, but I can't figure out how to remove this error:

    On this line:
    document.write("<a href=\"wherever.htm\">whatever</a>");

    W3C validator underlined the first \ and said:
    an attribute value must be a literal unless it contains only name characters

    What does it mean? How to validate this line?

    Any help will be appreciated.

    TY
     
    nabil_kadimi, Apr 27, 2007 IP
  2. rgchris

    rgchris Peon

    Messages:
    187
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Should probably just be able to use single quotes in lieu of one of the sets of double quotes and you'll be fine.
     
    rgchris, Apr 27, 2007 IP
  3. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #3
    Ok - it worked, but now I have


    document type does not allow element "a" here



    It's inside a <p><script> and </script></p> !!!
     
    nabil_kadimi, Apr 27, 2007 IP
  4. rgchris

    rgchris Peon

    Messages:
    187
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Do you have the full section of code by any chance? Do you have to use the "document.write" method?
     
    rgchris, Apr 27, 2007 IP
  5. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #5
    I use javascript for SEO reasons.

    here is the html

        
    <h6>Catégories:</h6>
        <p id="categories">
            <script type="text/javascript" language="javascript">
                 document.write("<a href='cars-0.htm'>Cars</a>");
                 document.write("<a href='Jobs-0.htm'>Jobs</a>");
                 document.write("<a href='and-so-on-0.htm'>and so on</a>");
            </script>
        </p>
    
    Code (markup):
     
    nabil_kadimi, Apr 27, 2007 IP
  6. diarmuid

    diarmuid Peon

    Messages:
    285
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    According to W3, all you need to do regarding atributes with XHTML, is quote them AKA put them in quotes.

    So regarding the original section of code:
    document.write("<a href=\"wherever.htm\">whatever</a>");
    <a href=\"wherever.htm\">whatever</a>
    
    Code (markup):
    So in the actual XHTML code part of the code... all you need to do is include the first \ in the quotes to make it XHTML compatible, however you probably shouldn't need to use a \ anyway...

    Ok hopefully that helped, if it didn't and if I've just gone off on a tangent just ignore me or slap me :D

    Diarmuid
     
    diarmuid, Apr 27, 2007 IP
  7. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #7
    Finally I remember.

    It was so obvious :<!-- and //-->

    The W3C Xhtml validation bot cannot read Javascript, thus, I have to tell him to escape it.

    of course!!!
     
    nabil_kadimi, Apr 30, 2007 IP
  8. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You need to wrap it in CDATA.

    <script type="text/javascript" language="javascript">
    <![CDATA[
    document.write("<a href='cars-0.htm'>Cars</a>");
    document.write("<a href='Jobs-0.htm'>Jobs</a>");
    document.write("<a href='and-so-on-0.htm'>and so on</a>");
    ]]>
    </script>
    Code (markup):
     
    Gordaen, Apr 30, 2007 IP