logo

Premium Support
24/7/365

Premium support customers may submit help-desk tickets using the form below.
Alternatively, the help-desk system can be accessed directly at support.maxiomtech.com. support@maxiomtech.com
info@maxiomtech.com
+1 (703) 942-9420
 

Request.QueryString in JavaScript

Request.QueryString in JavaScript

Request.QueryString in JavaScript

Every now and then I find myself needing this function in JavaScript so I end up writing it over and over again. So I decided to post it on our blog and file it under Tip-And-Tricks so I (and, yeah, you too!) can come back and get it when needed again.

So here we go:


<script type="text/javascript">
<!--

function qs(key) {
 //Get the full querystring
 fullQs = window.location.search.substring(1);
 //Break it down into an array of name-value pairs
 qsParamsArray = fullQs.split("&");
 //Loop through each name-value pair and
 //return value in there is a match for the given key
 for (i=0;i<qsParamsArray.length;i++) {
  strKey = qsParamsArray[i].split("=");
  if (strKey[0] == key) {
   return strKey[1];
  }
 }
}

//Test the output (Add ProductId to your URL)
var ProductId = QueryString("ProductId");
document.write("Product Id: " + ProductId + " - Full Query String: " + fullQs);

-->
</script>

<h3>Usage:</h3>


var&nbsp;myValue&nbsp;=&nbsp;qs(&amp;quot;key&amp;quot;)

Enjoy.

mm
Antonio Chagoury

Founder and CEO

No Comments

Sorry, the comment form is closed at this time.