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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with QueryString

    I have the following function:

    Code:
    function goToPageWithAttributes(page,attr,value){
            //alert("goToPageWithAttributes :" + page + " attr : " + attr + " value : " + value );
    
            var container = MyOpenSpace.MySpaceContainer.get();
            var qryString = container.getQueryString();
    
            var qryString = replaceQueryString(qryString,attr,value);
    
            alert(qryString)
    
            window.location = page + "?" + qryString
        }
    I am wondering how I would go about altering or using this function so that I am able to pass multiple attributes and values to it. In other words, I would like to generate a page similar to page.php?a=1&b=2&c=3&d=something&e=test.

    Any thoughts from anyone? Thanks in advance!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Code:
    function goToPageWithAttributes(page)
    {
       var qstr = '?';
       for (var a = 1; a < arguments.length; a += 2)
       {
          qstr += arguments[a] + '=' + arguments[a+1] + '&';
       }
       qstr = qstr.replace(/&$/, '');
       window.location = page + qstr;
    }
    That should help you build the querystring; pass it the page url, and as many attribute/value pairs as desired. You'll have to figure out how to integrate it with the rest of that code ...this:

    Code:
    var qryString = container.getQueryString();
    
            var qryString = replaceQueryString(qryString,attr,value);
    ... for one, doesn't make sense (declaring a var twice).
    Last edited by adios; 06-03-2009 at 05:10 PM.

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much for your snippet. It worked like a charm. As for the double declaration...this is a MySpace application so we are basically grabbing the MySpace provided arguments and appending them to the URL I am creating.

    Thanks again, much appreciated.


  •  

    Posting Permissions

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