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 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2011
    Location
    new york
    Posts
    105
    Thanks
    4
    Thanked 0 Times in 0 Posts

    concatenating multiple variables in a string?

    Not sure what the technical term for what I'm doing is but I think I'm trying to concatenate variables into a string.


    Code:
    xmlhttp.open("GET","http://www.website.com/here.php?q="+str,true);
    I had one variable at first, called str. Now I have three more (str2,str3,str4), and I want to assign them each to a GET variable.

    What is the proper syntax?

    I tried this but it did not work.

    xmlhttp.open("GET","http://www.website.com/here.php?q="+str+"&r="+str2+"&s="+str3+"&t="+str4,true);



    the URL should look like this
    http://www.website.com/here.php?q=st...&t=str3&u=str4

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Quote Originally Posted by phpchick View Post
    xmlhttp.open("GET","http://www.website.com/here.php?q="+str+"&r="+str2+"&s="+str3+"&t="+str4,true);
    Strange, because this is exactly how you should do it, if str, str2, str3 and str4 are Javascript variables and all of them are defined.

  • #3
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    216
    Thanks
    0
    Thanked 29 Times in 27 Posts
    Try this
    Code:
    xmlhttp.open("GET","http://www.website.com/here.php?q="+encodeURIComponent(str)+"&r="+encodeURIComponent(str2)+"&s="+encodeURIComponent(str3)+"&t="+encodeURIComponent(str4),true);
    And take care to the warning on this page (there is no need to decode).


  •  

    Posting Permissions

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