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 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2003
    Location
    Houston, Texas
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple select to JS array

    I am trying to submit several forms each containing a multiple select combo box and pass the results to another page. The problem I am having is when I select several options, only the first option is being sent to the next page. For example in the following code if I were to select options 1,2,3 and b,d only the values of 11111 and bbbbb are sent to the next page. Can anyone tell me where I'm missing the boat on this one?

    Thanks

    Harry

    <html>
    <Head>
    <script>
    function send_data()
    {
    document.form3.elements['fld1[]'].value = document.form1.elements['fld1[]'].value;
    document.form3.elements['fld2[]'].value = document.form2.elements['fld2[]'].value;
    document.form3.submit();
    return false;
    }
    </script>
    </head>

    <body><center>
    <form name="form1" onsubmit="return send_data">
    <select name="fld1[]" size = "5" multiple>
    <option value="11111">1</option>
    <option value="22222">2</option>
    <option value="33333">3</option>
    <option value="44444">4</option>
    <option value="55555">5</option>
    </select>
    </form>

    <form name="form2" onsubmit = "return send_data()">
    <select name="fld2[]" size = "5" multiple>
    <option value="aaaaa">a</option>
    <option value="bbbbb">b</option>
    <option value="ccccc">c</option>
    <option value="ddddd">d</option>
    <option value="eeeee">e</option>
    </select><br>
    <input type="submit">
    </form>

    <form name="form3" action="ary2.php" method="get">
    <input type="hidden" name="fld1[]">
    <input type="hidden" name="fld2[]">
    <form>
    </body>
    </html>
    Last edited by Harry; 07-11-2003 at 08:08 PM.
    Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Talk about doing this the hard way! You are only getting the first value from each of those selects because that's all you requested and all you made space for in the third form.

    Why three separate forms? Why not do this:

    Code:
    <html>
    <Head>
    </head>
    
    <body><center>
    <form name="form1" action="ary2.php" method="get">
    <select name="fld1[]" size = "5" multiple>
    <option value="11111">1</option>
    <option value="22222">2</option>
    <option value="33333">3</option>
    <option value="44444">4</option>
    <option value="55555">5</option>
    </select>
    <select name="fld2[]" size = "5" multiple>
    <option value="aaaaa">a</option>
    <option value="bbbbb">b</option>
    <option value="ccccc">c</option>
    <option value="ddddd">d</option>
    <option value="eeeee">e</option>
    </select><br>
    <input type="submit">
    <form>
    </body>
    </html>
    This code is much simpler and you'll end up with the multiple values being posted. Notice that no script is needed either.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    New Coder
    Join Date
    Jul 2003
    Location
    Houston, Texas
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I wish it was that easy but I have a page that requires 6 forms on it. The code I sent here was just for an example of what I am trying to do.

    Thanks for the reply anyway. This the best JS forum I have found.
    Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you're going to allow multiple selects then your hidden form will have to contain as many fields as there are select options or you'll have to stack multiple results into a single field and then parse them out on the server side (or next page).

    You should also be aware that when multiple selects are allowed the "selectIndex" value is pretty much worthless as it'll only tell you about one of the selected items. For multiple selects you have to iterate through the whole options list checking each option for whether it's selected or not.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    New Coder
    Join Date
    Jul 2003
    Location
    Houston, Texas
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Roy. I got it figured out now. I was able to create two functions to see what was selected and then I made a variable equal to the two functions concantenated together and it worked perfectly. Again, thanks for steering me in the right direction.
    Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."


  •  

    Posting Permissions

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