I am retrieving one query string parameter, and for that my code is
<a href="Default2.aspx?Id=1&status=pending&year=2010">Click me</a>
Now I want to retrieve “status=pending” and for that I am doing
var qString = window.location.search.substring(1);
var Keys = qString .split('&');
alert(Keys[1]);
This works fine, but I am hard-coding [1] here. is there any elegent way of doing this without hard-coding?
I’d use a regular expression such as:
This will retrieve only what the status is. If you already know the variable is always called status, but don’t know what the value is, this is the right way to go.
To use it, you’d have to do something like this:
Hope it helps