How can I replace Space with %20 in javascript?
replace replace("","%20");
with replace(/ /g,"%20");
http://www.w3schools.com/jsref/jsref_replace.asp
sParameter = encodeURIComponent(sParameter.trim()) //"Test%20-%20Text"
the .trim
will remove leading and trailing whitespace from the string. encodeURIComponent
will URL-encode it.
sParameter = encodeURIComponent(sParameter.trim())