Sunday, 11 February 2018

javascript - jQuery querystring






Possible Duplicate:
get querystring with jQuery






How do I get the value of a querystring into a textbox using jQuery?



Lets say the url is http://intranet/page1.php?q=hello




I would like the "hello" to be in the textbox.


Answer



In my programming archive I have this function:



function querystring(key) {
var re=new RegExp('(?:\\?|&)'+key+'=(.*?)(?=&|$)','gi');
var r=[], m;
while ((m=re.exec(document.location.search)) != null) r.push(m[1]);
return r;
}



You can use that to get the query string value and put in a textbox:



$('#SomeTextbox').val(querystring('q'));

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...