SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: query

  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    query

    Hey all.
    I have a page (g.shtml)
    and in that page I have a ssi to a php page (list.php)

    When the user is directed to that site from a link, a querystring is sent alongwith the values in "category" and "offset"
    looks oemthing lkie this:
    <a href="g.shtml?category=value&offset=value">

    In the ssi I need to use those variables as a querystring to the php file so it can be processed correctly.

    Now I need to figure out how to take those values from the original query string (using javascript) and then use the values to create the appropiate querystring to the php file.

    ideas? suggestions?

    thanx

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can access the url of a link or window with the window.location object.
    Code:
    var my_url = window.location.href;
    var my_data = my_url.split(/?/);
    Now my_data is an array with my_data[0] holding "g.shtml" and my_data[1] holding "category=value&offset=value." Now you two key=value pairs that you can access:
    Code:
    var my_data_pairs = split(/&/);
    Now my_data_pairs[0] = "category=value" and
    my_data_pairs[1] = "offset=value."
    If you want to load up an associative array then you can say:
    Code:
    var my_data = new Array();
    for (i = 0; i < my_data_pairs.length; i++)  {
        this_pair = my_data_pairs[i].split(/=/);
        my_data[this_pair[0]] = this_pair[1];
    }
    Hope this helps.
    <<< johnny chidiac
    johnnydaboy@mac.com


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
  •