...

View Full Version : Passing Values or Content using Params Using Javascipt



isaaclloyd
03-21-2005, 07:31 PM
Here is the script:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx!= -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
// End -->
</script>


Heres the address it uses when the form is submitted:


http://www.example.com/test.html?quantity=1&name=new+guy&address=1002+road etc....


Heres the Problem:


<SCRIPT LANGUAGE="JavaScript">
name = unescape(params["name"]);
address = unescape(params["address"]);
</SCRIPT>

SCRIPT OUTPUT:
Name = new+guy
Address = 1002+road


I need the output to be:


OUTPUT:
Name = new guy
Address = 1002 road


so it needs to change the "+" for a "space". Any help or comments is greatly apreciated.

~Isaac Lloyd~

A1ien51
03-21-2005, 08:33 PM
This should work....

name = unescape(params["name"]);
var regEx = /\+/gi;
name = name.replace(regEx," ");

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum