replacing %20

G

gkeogh

I have the followng code which reads in variables in the URL and
converts them to javascript vars.

<script language="JavaScript">
if (window.location.search.length>1){
Params = window.location.search.substring(1);
Pairs = Params.split("&");
for (i=0;i<Pairs.length;i++){
theVar = Pairs.split("=");
eval(theVar[0] +'="'+ theVar[1]+'"');
}
}


</script>
when i do a document.write, my vars are writing out, BUT the spaces are

all displayed as
%20 (see below)


%20API/Bulk%20Manufacturing,%20Finished%20Dose


I have tried a few ideas but cant replace the "%20" with a " "


Anyone any suggestions?


Cheers
Gary
 
W

web.dev

I have the followng code which reads in variables in the URL and
converts them to javascript vars.

<script language="JavaScript">
if (window.location.search.length>1){
Params = window.location.search.substring(1);
Pairs = Params.split("&");
for (i=0;i<Pairs.length;i++){
theVar = Pairs.split("=");
eval(theVar[0] +'="'+ theVar[1]+'"');
}
}


</script>
when i do a document.write, my vars are writing out, BUT the spaces are

all displayed as
%20 (see below)


%20API/Bulk%20Manufacturing,%20Finished%20Dose


I have tried a few ideas but cant replace the "%20" with a " "


Anyone any suggestions?


Cheers
Gary


Unescape your querystring with the unescape() function before you start
parsing it.

With that said, there are plenty of libraries out there which help
facilitate getting the name/value pairs from the querystring. You
should try to look them up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top