Pages

Monday 16 April 2012

Javascript Get the value of the specified Query String Parameter

This Javascript function checks the address of the current page for the supplied query string parameter. If found, the value of the parameter is used, if the parameter is not found, false is returned. See also: checkParemeterExists(), which returns true or false if the specified parameter is found or not.
       
function getParameter(parameter)
{
   fullQString = window.location.search.substring(1);
   paramArray = fullQString.split("&");
   
   found = false;
   for (i=0;i<paramArray.length;i++)
   {
     currentParameter = paramArray[i].split("=");
     if(currentParameter[0] == parameter)
        return currentParameter[1];
   }
   return false; //Not found
}
       
 

No comments:

Post a Comment

Popular Posts