Given the search or query string from a URL ...
var searchStr = location.search;
How would i write a function, replace(paramName, paramVal), to replace
the value in the query string belonging to the param name,
"paramName", or, if there is no "paramName" given in the query string,
add it to the existing query string?
Thanks for your help, - Dave
http://lmgtfy.com/?q=how+to+replace+param+in+url
1st link looks good....
http://www.webmasterworld.com/javascript/3986111.htm
--
Luuk
You could use a keyboard.
<http://www.catb.org/~esr/faqs/smart-questions.html>
PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300...@news.demon.co.uk> (2004)
Untested, but possibly something like:
first protect paramName and paramVal with one
of the encoding functions:
escape(), encodeURI(), or encodeURIComponent()
and then
var re = new RegExp('\\?' + paramName + '=[^?]*');
var newItem = '?' + paramName + '=' + paramVal;
var newSearchStr = (('?'+searchStr)
.replace(re, "") + newItem).substr(1)
Csaba Gabor from Vienna