If its the first time visiting the site and no querysting has been added or if there is only one querystring attached to the url '?hos' like http://hospitalsite/events/Pages/default.aspx?hos=somevalue, then i need to apply the if condition..the else condition is working fine..How do I check to see if there is a query
$(".hospitalDropDown").change(function(e){
currentURL=$(location).attr('href');
if((currentURL == 'http://hospitalsite/events/Pages/default.aspx' or (....)) {
window.location.href= 'http://hospitalsite/events/Pages/default.aspx'+'?hos='+$(this).val();
} else {
window.location.href = ( $(this).val() == "All Hospitals" ) ? 'http://hospitalsite/events/Pages/default.aspx': currentURL +'&hos='+ $(this).val();
}
});
I think you'd like this value:
var queryString = window.location.search;
If your URL was "http://www.google.com/search?q=findme", then the above queryString
variable would be equal to "?q=findme".
You can check if that is non-empty to see if there is a query string or not.
Not totally sure about the entire query string, but this will help you check if there are individual variables in the query string:
var $_GET = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
function decode(s) {
return decodeURIComponent(s.split("+").join(" "));
}
$_GET[decode(arguments[1])] = decode(arguments[2]);
});
document.write($_GET["test"]);
This question has some more answers that might point you in the right direction:
how to get GET and POST variables with JQuery?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With