I still at the newbie stage as far as Javascript goes. How do you return a URL's Querystring using Javascript?
Printable View
I still at the newbie stage as far as Javascript goes. How do you return a URL's Querystring using Javascript?
Hey Nator.
I have the same question. Sorry I wish I could help. if you find Out could you e-mail me. I will do the same. [email protected]
Thanks
"B"
Not certain if there is a built in function for it, but you could just put the URL into a string object and parse it for:
If you copy this into a HTML document in your wwwroot folder for IIS and call it with a querystring, when you click on the button it will pop up a dialog with just the querystring. (You can't specify querystrings when calling a file locally.. at least I couldn't)Code:<html>
<head>
<title>Select the products...</title>
<meta name="Microsoft Theme" content="none">
<script language="JavaScript">
function SearchDemo()
{
var r, re, ln; //Declare variables.
var qs = new String('');
var s = new String(document.URL);
re = "[?]"; //Create regular expression pattern.
r = s.search(re); //Search the string.
if (r != -1)
{
ln = s.length;
qs = s.substring(r, ln);
}
return(qs); //Return the Boolean result.
}
function cmdDisplay_onclick()
{
window.alert(SearchDemo());
}
</script>
</head>
<body>
<input onclick="cmdDisplay_onclick()" type=button name=cmdDisplay value="ClickMe!">
</body>
</html>
That should get you close..
Use:
var myQuery;
myQuery = location.search;
This will return everthing from the "?" on. Then you can use the split() function to split the string on the "&"s, assuming that you have more than one value.
Chris