SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Houston
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help passing multiple variables via url

    Hey guys, I need you help. I'm new to Java (and find it's a necessary evil), and I'm new to programming (about 3 weeks), so bare with me.

    I'm trying to pass multiple variables using a url on a Java function call.
    the code I have that passes the 1 variable is:


    function HandleChange() {
    parent.CustomerIf.document.location.href="CustomerReturn.asp?id=" + varName.options[varName.selectedIndex].text;
    }


    which passes the chosen data (being loaded from a database) from a drop down box on an onchange event in asp script.

    What I want to do is pass multiple variable via the above url script that the next page will get by the request.querystring method.

    something like this:

    function HandleChange() {
    parent.CustomerIf.document.location.href="CustomerReturn.asp?id=" + varName.options[varName.selectedIndex].text + "address=" varAddress.value;
    }
    I'm know the syntax is not right, but you get the idea.
    thanks for any help.

    Lee

  2. #2
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the correct syntax!

    http://www.domainname.com/cgi-bin/cg...1&name2=value2

    Check out this page it could be really helpfull?

    http://ashutoshsaxena.tripod.com/jst.../realjs11.html

  3. #3
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you're far off, but I can't quite work out what you're doing there [img]images/smilies/smile.gif[/img]

    You can separate any number of URL parameters with separators of your choice (although question mark is the most usual). You might want to try the following method to make the code more readable:

    var first_param_val = "?id=" + varName.options[varName.selectedIndex].text;
    var second_param_val = "?parm2=" + "something else";
    var third_param_val = "?parm3=" + "another value";
    document.location.href="PageToCall.asp?" + first_param_val + second_param_val + third_param_val;


    Just a suggestion.

    By the way, don't confuse Java with Javascript. It's not the same [img]images/smilies/smile.gif[/img]


    Andy
    P.S.
    Apologies for the formatting. No matter what I try, I can't make the code tag in this editor accept hard-returns
    From the English nation to a US location.

  4. #4
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Houston
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, I've changed my function to this:

    function HandleChange() {
    var Name_val = "?id=" + varName.options[varName.selectedIndex].text;
    var Address_val = "&address=" + varName.options[varName.selectedIndex].text;

    parent.CustomerIf.document.location.href="CustomerReturn.asp" + Name_val + Address_val;
    }

  5. #5
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Houston
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, I've changed my function to this:

    function HandleChange() {
    var Name_val = "?id=" + varName.options[varName.selectedIndex].text;
    var Address_val = "&address=" + varName.options[varName.selectedIndex].text;

    parent.CustomerIf.document.location.href="CustomerReturn.asp" + Name_val + Address_val;
    }

    I had to change to a '&' in the second variable to seperate the strings and removed the '?' in the href. (I used the same variable refernce for the value in the second var just as a test - I will have to assign it a different value once I generate it)


    Thanks for your help guys!
    Lee


Bookmarks

Posting Permissions

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