Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can i pass the plus(+) sign throw the location.href?

    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

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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();
    Last edited by beetle; 10-07-2003 at 07:55 PM.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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'));">

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    var sEscapedPlus = '%' + '+'.charCodeAt().toString(16);
    sString=sString.replace(/\+/g, sEscapedPlus)
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I changed my post
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #6
    Regular Coder
    Join Date
    Sep 2003
    Posts
    290
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I changed my post
    You still need to esacape the plus for the name, however.

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oops. Easy to fix
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •