...

View Full Version : How can i pass the plus(+) sign throw the location.href?



frontline
10-07-2003, 10:06 AM
Hello
im loading new page with simple js function something like : location.href="http://www.blah.com?foo=x+4"
now when i getting the request parsing on server side the plus(+) sign is turning to blank space.
how can i pass the plus(+) sign so it wont be blank space but the actual plus(+) string
thanks

beetle
10-07-2003, 10:38 AM
function QueryString()
{
this.qs = "";
this.vars = new Array();

this.add = function( name, value )
{
this.vars[this.vars.length] = prepare( name ) + "=" + prepare( value );
function prepare( str )
{
return escape( str ).replace( /\+/g, "%2B" );
}
}
this.generate = function()
{
return "?" + this.vars.join( "&" );
}
}

var uri = "http://www.blah.com";
var qs = new QueryString();
qs.add( "foo", "x+4" );

location.href = uri + qs.generate();

frontline
10-07-2003, 10:58 AM
ok
this is of course what is did .. but if you notice (do simple alert test)
you will see that the escape() function don't change the plus(+)
sign.. so there i left with the plus(+) that converts to blank space


<input type="button" value="Escape this!" onclick="alert(escape('foo=x+4'));">

liorean
10-07-2003, 12:36 PM
var sEscapedPlus = '%' + '+'.charCodeAt().toString(16);
sString=sString.replace(/\+/g, sEscapedPlus)

beetle
10-07-2003, 06:23 PM
I changed my post

Jeff Mott
10-07-2003, 07:36 PM
I changed my postYou still need to esacape the plus for the name, however.

beetle
10-07-2003, 08:53 PM
oops. Easy to fix :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum