Querystring - Add value to specific variable
Hi,
I have this script, it passes the querystring to the next page if you click an <a href>
And it adds the value "10". The problem is that it adds "10" to the last value.
I want it to add 10 to just the value I want.
Example: www.mypage.com?test=123&hello=321
How would I do it if I just wanted the "10" on the test variable (but only if variable "test" exist) so it would turn out to:
www.mypage.com?test=12310&hello=321
Apprecite any help, thanks
// Daniel
My script:
$('a').attr('href', function (index, value) {
// If there is a query string appy this to links.
if (window.location.search) {
// If the link allready contains a question mark add the query
// string with an ampersand instead.
if (value.indexOf('?') > -1) {
return value + '&' + window.location.search.substr(1);
}
return value + window.location.search + 10;
}
});