I'm wanting to get data from the URL query string and display it in the body of an HTML document. I can't get the script to replace the + signs with an empty space.
Example URL: www.mywebsite.com/?item=Sandwich&bread=White+Bread
In the HTML body, the text field for item would show "Sandwich" but the text field for bread would show "White+Bread." How can I replace the + with a space?
Here's the function Im using to get value from the URL
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;
}
$("span.item").text(querystring('item'));
$("span.bread").text(querystring('bread'));
I've tried using this but it's telling me arrays don't have a replace function.
.replace(/\+/g, ' ')