This function works only for a parameter.
function getQueryStringValue(key) {
debugger;
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
};
Please I need a JavaScript function that can retrieve more than one querystring parameter, I need to pass the name of the parameter as key to the function. Thank you
The function in the link Alex shared is as below
function getParameterByName(name, url) { if (!url) { url = window.location.href; } name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); };
With my url as this:
var url= 'search-results.html?param1=unth?param2=lagos';
And I pass this to the function :
var param1 = getParameterByName('param1'); var param2 = getParameterByName('param2');
It return param1 as : luth?param2=lagos instead of luth.
This is the same issue with the function I shared. My question is a JavaScript Function that retrieves multiple querystring parameter but the function works only for one parameter