I would like to check the querystring to see if a variable exists.
EXAMPLE:
www.somesite.com?groupid=123
If groupid exists in the querystring and has ANY value then show a hidden div (#closedMsg). I do not care what the value of the groupid is I just want to verify that it has a value.
If the url looks like this “www.somesite.com?groupid=” with no value for groupid, I do not want to show the hidden div.
Here is my code so far which targets for a value of 123, how do I make it accept any value for groupid?
<script type="text/javascript" charset="utf-8">
// ***this goes on the global scope
// get querystring as an array split on "&"
var querystring = location.search.replace( '?', '' ).split( '&' );
// declare object
var queryObj = {};
// loop through each name-value pair and populate object
for ( var i=0; i<querystring.length; i++ ) {
// get name and value
var name = querystring[i].split('=')[0];
var value = querystring[i].split('=')[1];
// populate object
queryObj[name] = value;
}
// ***now you can use queryObj["<name>"] to get the value of a url
// ***variable
if ( queryObj[ "groupid" ] === "123" ) {
var $messageDiv = $('#closedMsg'); // get the reference of the div
$messageDiv.show().html('yay, value of groupid exists');
}
</script>
THANKS EVERYONE!