SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    & doesn't get parsed.

    Hi,

    I'm developing a site where adherence to the w3c spec is important...the spec i've agreed with my clientis that all the pages are html compliant.

    I have this bit of code to make a re-load happen to empty the $_POST so users don't get the the page you are trying to view contains postdata popup.

    Code JavaScript:
    function doReload(queryvalue){
    	document.location = 'http://www.website.com/results.php?s=mens&category=t-shirts&sort=' + queryvalue;
      }

    the & causes validation errors but if i put an & in there it gets taken literally and doesn't get parsed as an ampersand.....consequently the page breaks.

    any ideas how i can inlude the & in my string and have it parsed correctly

    thanks

  2. #2
    SitePoint Member
    Join Date
    Dec 2007
    Location
    Germany, Hannover
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For URLs, you need special encoding, not the same as for html.
    Vou probably have to replace your ampersand by this:
    %26.
    I havn't tried this. Just got the information here:
    http://www.blooberry.com/indexdot/ht...rlencoding.htm
    Hope I've put you on the right track here ;-)
    HTH

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Yes thats it. Nice one Roland

  4. #4
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Noooo... don't do that!

    Since the js code is inline use this:

    HTML Code:
    <script type="text/javascript">
    //<![CDATA[
    
    ALL YOUR JS CODE BELONGS IN HERE
    
    //]]>
    </script>
    Than the validator won't complain.

    &#37;26 means to pass the actual ampersand as DATA but you DON'T want that because the ampersand is what separates GET data.

  5. #5
    SitePoint Member
    Join Date
    Dec 2007
    Location
    Germany, Hannover
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm, sounds like it makes sense, I must admit!

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by M-M-J View Post
    Noooo... don't do that!

    Since the js code is inline use this:
    You could also make the code not inline and link to an external js file. I think that would solve the validator error.

    Or, you could create a function in an external JS file that builds the query for you. The inline script on your page would call the function and pass it an array of values. That external function would insert the '&' where necessary.

    - Walkere

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI guys...thanks for the replies....i've moved it to an external file now

  8. #8
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elduderino View Post
    HI guys...thanks for the replies....i've moved it to an external file now
    You changed &#37;26 back to &, right?

  9. #9
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes i have...thanks


Bookmarks

Posting Permissions

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