www.webdeveloper.com
Results 1 to 3 of 3

Thread: Populate Array from select drop lists

  1. #1
    Join Date
    Jul 2012
    Posts
    3

    Populate Array from select drop lists

    Hello guys,

    I want to populate an Array from the selections of 4 select drop down lists.
    Could you please give me a hand here.

    All the help is much appreciated.

    What my code looks like at the moment :

    <select id="prwto" name="first">
    <option id="red" value=1>Red</option>
    <option id="yellow" value=2>Yellow</option>
    <option id="blue" value=3>Blue</option>
    <option id="green" value=4>Green</option>
    </select>

    var choices = [document.first.selectedIndex];

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,373

    Lightbulb

    This is my guess as to what it is that you are trying to do.

    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    
    <script type="text/javascript">
    var choices = [];
    function saveSelections(info) {
     if (info.value != '') {
       choices.push(info.value+' : '+info.options[info.selectedIndex].text);
     }
    }
    function showSelections() { alert(choices.join('\n')); }
    </script>
    
    </head>
    <body>
    <form name="myForm" action="" method="post" onsubmit="return false">
    <select id="prwto" name="first" onchange="saveSelections(this)">
     <option value="">Choose</option>
     <option value=1>Red</option>
     <option value=2>Yellow</option>
     <option value=3>Blue</option>
     <option value=4>Green</option>
    </select>
    <button onclick="showSelections()">Show choices</button>
    </form>
    </body>
    </html>
    Please use [ code] and [ /code] tags (without the spaces) around your script submissions.
    Makes it a lot easier for forum readers to see and preserves formatting.

    Good Luck!

  3. #3
    Join Date
    Jul 2012
    Posts
    3
    Thanks for the help and for the [code] info!
    I'll give it a try

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles