Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: &

  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,958
    Thanks
    120
    Thanked 76 Times in 76 Posts

    &

    I'm changing href attributes with js into something like:

    &p1=100&p2=10.....

    when html walidator reads page with that, it does not like it.

    How to handle that ?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Just what the validator tells you to do:

    xxxx.php?foo=7&p1=100&p2=10

    But the browsers aren't as fussy as the validator.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,958
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Thanks. Looks like this will work.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,189
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by BubikolRamios View Post
    I'm changing href attributes with js into something like:

    &p1=100&p2=10.....

    when html walidator reads page with that, it does not like it.

    How to handle that ?
    how does a validator see the result of javascript execution?
    normally, you validate just the hard-coded html of a page.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    When you code something like this:
    Code:
    <script type="text/javascript">
    document.write('<a href="xyz.php?page=1&whack=me">do it</a>');
    </script>
    The validator will complain, technically correctly, about that &.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,189
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by Old Pedant View Post
    When you code something like this:
    Code:
    <script type="text/javascript">
    document.write('<a href="xyz.php?page=1&whack=me">do it</a>');
    </script>
    The validator will complain, technically correctly, about that &.
    inline javascript using XML reserved characters should wrap the program body in CDATA "comments", which will solve the validation issue without junking up the plain text javascript. hard-escaping the reserved chars could cause portability issues.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by rnd me View Post
    inline javascript using XML reserved characters should wrap the program body in CDATA "comments",
    Agreed. But you asked.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,958
    Thanks
    120
    Thanked 76 Times in 76 Posts
    so, this is not resolved.
    Validator does not complain if js generated link contains:
    Code:
    ...?p100=12&amp;selection=1
    but cant read selection parameter on server (after link click )then, unless it is :
    Code:
    ?p100=12&selection=1
    any suggestion ?

    I guess CDATA, cant be used as it comes out as plain text from js.
    Last edited by BubikolRamios; 12-22-2010 at 06:35 PM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #9
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Try using the //<![CDATA[ and //]]>.

    For example.
    Code:
    <script type="text/javascript">
    //<![CDATA[
    document.write('<a href="xyz.php?page=1&whack=me">do it</a>');
    //]]>
    </script>
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • Users who have thanked DJCMBear for this post:

    BubikolRamios (12-22-2010)

  • #10
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,958
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Seems this will work & validate. Thanks.
    Code:
    result = result.replace("&","//<![CDATA[" + "&amp;" + "//]>");
    Last edited by BubikolRamios; 12-22-2010 at 08:33 PM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #11
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Quote Originally Posted by BubikolRamios View Post
    Seems this will work. Thanks.
    Code:
    result = result.replace("&","//<![CDATA[" + "&amp;" + "//]>");
    That isn't a good thing to do it makes more work for you and may slow down the codes as it will have to replace every & sign why not just do this.

    Code:
    <script type="text/javascript">
    //<![CDATA[
      // All your javascript codes here
    //]>
    </script>
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #12
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,958
    Thanks
    120
    Thanked 76 Times in 76 Posts
    so basicaly, you are saying that ewery js file should have
    <![CDATA[ at top and
    and
    //]>
    at bottom ?

    What if there is
    xxx.innerHTML = "<...."
    inside js
    will that work ?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #13
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Not in a .js file no only use them comment tags when you put javascript codes on the page itself so only use them on the codes that if you view the source code you can see it, as the validator only obtains the files source code and checks it for errors and them comment tags say this is a comment but still runs the codes between them, if this makes sense to you.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •