Let’s say I’m on a page on my website: http://www.example.com/SearchResults.asp?Search=stackoverflow. Is it possible to use a JavaScript or jQuery code to get the variable “search” from the URL string and populate it into the value of the search box?
Basically I’ll have my regular identified search box:
<input type="text" title="Search" id="search_box" />
And a user will search for something, but I will want a JavaScript or jQuery code that will get the value from the “search” variable in the URL string when the customer is on the Search.asp page and add it as the “value” to the input#search.
So the user will be on this page: http://www.example.com/SearchResults.asp?Search=stackoverflow and the search box will look like:
<input type="text" title="Search" id="search_box" value="stackoverflow" />
Thanks
You could try this function:
If this function is present in the sample you mentioned above, all you would call getSearchVariable(“Search”) to have “stackoverflow” returned.
So in your page, you would have a script element that looks like:
Hope that helps!