Tuesday, April 2, 2013

how to get the parameter value from a url?

Here is a easy to read and understand JS function that you can use to retrieve any variable from url.

All you need to do is call this function with name of the variable that you want to filter and it will return the value back to you.

Hope it helps:


function getURLParameter(name) {
                return decodeURI(
                    (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
                );              
            }
            var paramValue = getURLParameter('paramName');
            //alert(paramValue);

NOTE:
  • Replace 'paramName' with parameter for which you are looking to get value.
  • Variable 'paramValue' stores the parameter value.

No comments:

Post a Comment

your comments.....