Results 1 to 3 of 3

Thread: Populate Array from select drop lists

  1. #1
    Join Date
    Jul 2012

    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>

    var choices = [document.first.selectedIndex];

  2. #2
    Join Date
    Dec 2005


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

    <!DOC HTML>
    <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')); }
    <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>
    <button onclick="showSelections()">Show choices</button>
    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
    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