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”);
Categories: Work
JavaScript, Prefill List Form, SharePoint 2010
Comments (0)
Trackbacks (0)
Leave a comment
Trackback