Looking for Parse Query String Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis M. Marks

    Looking for Parse Query String Function

    I am looking for a javascript function that will parse a query string.
    Parameters are passed in the url: url?a=3&c=5&etc
    An array is returned that uses the variable name as the index.
    array["a"]=3
    array["c"]=5
    etc.

    --
    Dennis M. Marks

    Replace domain.invalid with dcsi.net


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
  • Dennis M. Marks

    #2
    Re: Looking for Parse Query String Function - ignore

    In article <05032004182856 1943%denmarks@d omain.invalid>, Dennis M.
    Marks <denmarks@domai n.invalid> wrote:
    [color=blue]
    > I am looking for a javascript function that will parse a query string.
    > Parameters are passed in the url: url?a=3&c=5&etc
    > An array is returned that uses the variable name as the index.
    > array["a"]=3
    > array["c"]=5
    > etc.[/color]

    I found the answer. Thanks

    --
    Dennis M. Marks

    Replace domain.invalid with dcsi.net


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

    Comment

    • Jeff North

      #3
      Re: Looking for Parse Query String Function

      On Fri, 05 Mar 2004 18:28:56 -0800, in comp.lang.javas cript "Dennis M.
      Marks" <denmarks@domai n.invalid> wrote:
      [color=blue]
      >| I am looking for a javascript function that will parse a query string.
      >| Parameters are passed in the url: url?a=3&c=5&etc
      >| An array is returned that uses the variable name as the index.
      >| array["a"]=3
      >| array["c"]=5
      >| etc.[/color]
      This is not exactly what you wanted but it might be a start.

      <script TYPE="text/javascript">
      var hrf, qs = new String(), arr = new Array();

      //--- url: test.htm?a=1234 5.6789&c=apple pie&d=52

      //--- get url line
      hrf = new String(document .location.href) ;

      //--- remove %20 codes and replace with spaces
      //--- will need to do this for other url characters
      hrf = hrf.replace(/\%20/g," ");

      //--- find start of querystring
      qs = "&" + hrf.substr(hrf. indexOf("?")+1 );

      //--- remove &a= from querystring
      qs = qs.replace(/\&[A-Za-z0-9]\=/g,",");

      //--- string now looks like ,12345.6789,app le pie

      //--- split into an array
      arr = qs.split(",");

      /*
      array looks like
      arr[0] = ,
      arr[1] = 12345.6789,
      arr[2] = "apple pie",
      arr[3] = 52
      */
      for( var ct=0; ct< arr.length; ct++)
      document.write( "arr["+ ct + "]=" + arr[ct] + "<BR>" );

      document.write( "WRONG: " + (arr[1] + arr[3]) + "<BR>");
      document.write( "RIGHT: " + (parseFloat(arr[1]) + parseInt(arr[3])) );
      </script>
      ---------------------------------------------------------------
      jnorth@yourpant sbigpond.net.au : Remove your pants to reply
      ---------------------------------------------------------------

      Comment

      • Robert

        #4
        Re: Looking for Parse Query String Function - ignore

        In article <05032004183352 9749%denmarks@d omain.invalid>,
        "Dennis M. Marks" <denmarks@domai n.invalid> wrote:
        [color=blue]
        > In article <05032004182856 1943%denmarks@d omain.invalid>, Dennis M.
        > Marks <denmarks@domai n.invalid> wrote:
        >[color=green]
        > > I am looking for a javascript function that will parse a query string.
        > > Parameters are passed in the url: url?a=3&c=5&etc
        > > An array is returned that uses the variable name as the index.
        > > array["a"]=3
        > > array["c"]=5
        > > etc.[/color]
        >
        > I found the answer. Thanks[/color]

        Please share.

        Thanks.

        Robert

        Comment

        Working...