javascript w3 strict xhtml validation (how to)

Discussion in 'JavaScript' started by boobird, Feb 16, 2009.

  1. #1
    I am wondering if you can help me with a problem for javascript xhtml strict validation.

    There is a protocol when using strict XHTML that all javascript should be
    removed from the XHTML, and while we have done this for the majority of
    elements, almost every form the site has requires javascript inline.

    As an example, javascript uses the "&" character a lot, where as XML requires this to be "&", which we can not use in javascript.

    Any suggestions?

    1) We can keep the site as Strict XHTML and validate everything BUT the
    javascript components, but this will result in lots of validation errors if
    tested.

    2) We can validate only for XHTML transitional. This would allow for 100%
    validation.
     
    boobird, Feb 16, 2009 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    You need to get rid of your inline usage of javascript and attach event listeners in an Init style loaded event handler.

    I switched to transitional and saved myself a ton of headaches in general, not just with JS.
     
    joebert, Feb 16, 2009 IP
  3. gnp

    gnp Peon

    Messages:
    137
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If with inline you mean directly on the form elements or the form tag then no .. only the suggestion by joebert will do..

    if how ever you mean that you have to define <script> tags in your source with the custom functions for each form then besides external files you could consider the CDATA section ..
    
    <script type="text/javascript">
    <!--<![CDATA[
    
    alert('test & test');
    // this will validate because it is contained in the CDATA section and the parser ignores it ;)
    //]]>-->
    </script>
    HTML:
    but from your post i do not think that will do... had to post it though :)
     
    gnp, Feb 18, 2009 IP