title: JavaScript function for retrieving multiple querystring values
body: <p>This function works only for a parameter.</p>
  
  <pre><code>function getQueryStringValue(key) {
     debugger;
     return unescape(window.location.search.replace(new RegExp("^(?:.*[&amp;\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&amp;") + "(?:\\=([^&amp;]*))?)?.*$", "i"), "$1"));
  };
  </code></pre>
  
  <p>Please I need a JavaScript function that can retrieve more than one querystring parameter, I need to pass the name of the parameter as key to the function. Thank you</p>
  
  <p>The function in the link Alex shared is as below</p>
  
  <pre>
  
      function getParameterByName(name, url) {
          if (!url) {
              url = window.location.href;
          }
          name = name.replace(/[\[\]]/g, "\\$&");
          var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
              results = regex.exec(url);
          if (!results) return null;
          if (!results[2]) return '';
          return decodeURIComponent(results[2].replace(/\+/g, " "));
      };
  
  </pre>
  
  <p>With my url as this:</p>
  
  <pre>
  
  
  
         var url= 'search-results.html?param1=unth?param2=lagos';
  
  </pre>
  
  <p>And I pass this to the function :</p>
  
  <pre>
  
       var param1 = getParameterByName('param1');
       var param2 = getParameterByName('param2');
  
  </pre>
  
  <p>It return param1 as : luth?param2=lagos
  instead of luth.</p>
  
  <p>This is the same issue with the function I shared.
  My question is a JavaScript Function that retrieves multiple querystring parameter but the function works only for one parameter</p>