...

View Full Version : Help with QueryString



mikeurturn
06-03-2009, 04:41 PM
I have the following function:


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!

adios
06-03-2009, 05:05 PM
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:


var qryString = container.getQueryString();

var qryString = replaceQueryString(qryString,attr,value);

... for one, doesn't make sense (declaring a var twice).

mikeurturn
06-03-2009, 07:05 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum