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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts

    :: using multiple select boxes and javascript ::

    atm im using a few select boxes that are created dynamically for part of a corporate wan.

    <select name="projectFileLocation">
    <option value="" selected></option>
    <option value="Boston">Boston</option>
    <option value="Inverness">Inverness</option>
    <option value="Lincoln">Lincoln</option>
    <option value="Swinderby">Swinderby</option>
    </select>

    now, on some of these menus i want the user to be able to select multiple values so i added the 'multiple' in the tag - that allows me to select more than 1 - problem is i am using a javascript method to create a url from the selected options on the page - this then creates a search

    basically i wanna know how to get the multiple values from the multiple select as form.element.value dont work - it just gets the 1st one

    thanks!

    (cant show the page as its hosted internally and contains sensitive info)
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe this will help:
    <html>
    <head>
    <title>Drop Down TEst</title>
    <script language="JavaScript">
    function disp(frmobj)
    {
    len=frmobj.mysel.length
    myval=""
    for(i=0;i<len;i++)
    {
    if(frmobj.mysel.options[i].selected)
    {myval+=frmobj.mysel.options[i].value}
    }
    alert(myval)
    }
    </script>
    </head>
    <body>
    <form name="myform">
    <select name="mysel" multiple>
    <option value="some value 1">Click Me</option>
    <option value="some value 2">Click Me</option>
    <option value="some value 3">Click Me</option>
    <option value="some value 4">Click Me</option>
    </select>
    <input type="button" value="Click Me" onClick="disp(this.form)">
    </form>
    </body>
    </html>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts
    thanks - got tied up doing other stuff 2day now - will lookk tomorrow - i assume this will work with a few select boxes on the same page as i have about 6 that are used to build the custom search
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As writen it will only work with the one select. I will see what I can do to modify so that it will work with more that one and post the code here.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the code modified to work with more than one select:
    <html>
    <head>
    <title>Drop Down TEst</title>
    <script language="JavaScript">
    function disp(frmobj)
    {
    len=frmobj.length
    myval=""
    for(i=0;i<len;i++)
    {
    if(frmobj.options[i].selected)
    {myval+=frmobj.options[i].value}
    }
    alert(myval)
    }
    </script>
    </head>
    <body>
    <form name="myform">
    <select name="mysela" multiple>
    <option value="some value 1">Click Me</option>
    <option value="some value 2">Click Me</option>
    <option value="some value 3">Click Me</option>
    <option value="some value 4">Click Me</option>
    </select>
    <input type="button" value="Click Me" onClick="disp(document.myform.mysela)">
    <select name="myselb" multiple>
    <option value="some value 1">Click Me</option>
    <option value="some value 2">Click Me</option>
    <option value="some value 3">Click Me</option>
    <option value="some value 4">Click Me</option>
    </select>
    <input type="button" value="Click Me" onClick="disp(document.myform.myselb)">
    </form>
    </body>
    </html>

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    518
    Thanks
    25
    Thanked 0 Times in 0 Posts
    thanks m8 - will try and get a look at it today
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

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