Web Analytics Made Easy -
StatCounter Retrieving Parameters passed within the URL - CodingForum

Announcement

Collapse
No announcement yet.

Retrieving Parameters passed within the URL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieving Parameters passed within the URL

    We need to retrieve parameters passed from one page to another, that have been added to the end of the URL with the ?fieldname=sssssss&2ndfield=ttttt.

  • #2
    With javascript, I assume?
    http://www.ipwebdesign.net/useful_parseUrl.html

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

    Comment


    • #3
      A more generic solution.

      http://www.codingforum.net/showthread.php?t=25786
      Glenn
      vBulletin Mods That Rock!

      Comment


      • #4
        Code:
        function parseQueryString() {
        var url = document.location.href;
        var qryStr = url.substr(url.indexOf("?")+1);
        var params = new Array();
        var splits = qryStr.split("&");
        for ( i = 0; i < splits.length; i++ ) {
          var actual = splits[i].split("=");
          params[actual[0]] = actual[1];
        }
        return params
        }
        You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

        Comment


        • #5
          Originally posted by shyam
          Code:
          function parseQueryString() {
          var url = document.location.href;
          var qryStr = url.substr(url.indexOf("?")+1);
          var params = new Array();
          var splits = qryStr.split("&");
          for ( i = 0; i < splits.length; i++ ) {
            var actual = splits[i].split("=");
            params[actual[0]] = actual[1];
          }
          return params
          }
          That's incomplete. You have to unescape the key-value pair and replace +'s with spaces and allow multiple values with keys of the same name, etc. The link I posted seems to be the most robust parse URL script I've seen.
          Glenn
          vBulletin Mods That Rock!

          Comment


          • #6
            wow! thanx for the pointer
            You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

            Comment

            Working...
            X