javascript - How do I grab part of a URL string and make it display as text in the HTML? -
say have url "www.example.com/example.html?storeid=1400&shopperid=1200" , want pull information shopperid equals, in example 1200.i added script header added html. why not working?
js:
function getparameterbyname(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new regexp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeuricomponent(results[1].replace(/\+/g, " ")); } var shopperid = getparameterbyname('shopperid');
your url isn't formatted correctly. have 2 ?, second should &.
"www.example.com/example.html?storeid=1400?shopperid=1200"
to:
"www.example.com/example.html?storeid=1400&shopperid=1200"