Javascript Get the value of the specified Query String Parameter - Code-Tips.com - Web Development, Programming, SEO

Sunday, February 13, 2011

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
}


Next: Javascript Get all parameters and values as an Array

Previous: Javascript Remove a parameter from the query sring if found in current url

Javascript Query String Manipulation (TOC)

0 comments:

Post a Comment