Home > Work > Useful JavaScript Function: Retrieve Query String Value

Useful JavaScript Function: Retrieve Query String Value

Quite often during my implementations I need to retrieve values from the query string to use as prefill values or perhaps redirect users to another page where I am using the Query String URL Filter.

1 function querySt(ji) { 2 hu = window.location.search.substring(1); 3 hu = hu.toLowerCase(); 4 gy = hu.split("&"); 5 6 for (i=0;i<gy.length;i++) { 7 ft = gy[i].split("="); 8 9 if (ft[0] == ji) { 10 return ft[1]; 11 } 12 13 } 14 15 return ""; 16 }

Usage:

  • Parameter: String – in lowercase (to avoid any confusion or mismatches)
  • querySt(“string”);

For Example:

URL: http://servername/pages/test.aspx?ProjectID=PRJ0001

To retrieve the ProjectID value call the function as follows:

  • querySt(“projectid”);
Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: