How to check if Url parameter is Empty or not?

Hi there
This question is related to

which I have asked before.

Now there is slight variation I am sending parameter as hashMap from server side script.How to detect that a parameter contain some value with it or not?

http://www.technicaloverload.com/get-value-url-parameters-using-javascript/

window.location.search will get the ? and everything after it in a URL with parameters. If you use substring(1), you will eliminate the ? and get only the params.

If you check for the indexOf() of # in the window.location.search, you can get the zero-index location of the hash, check everything after that using substring({hash index + 1}) will get you the hashMap value.

HTH,

:slight_smile:

The above can be simplified by using this getUrlParam function:

function getUrlParam(name) {
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return (results && results[1]) || undefined;
}

For example:

var id = getUrlParam('id');
if (id > "") {
    // do something with the id
} else {
    // there is no id value
}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.