Drop down list problem

Discussion in 'JavaScript' started by Dimension, Feb 18, 2008.

  1. #1
    I am trying to populate a drop down list based on another one. For example, the first drop down list has a selection of choices in it and next to it is an empty drop down box.

    Each time I choose a value from the first box, it will jump over to the second box. Is there a way for me to do this?
     
    Dimension, Feb 18, 2008 IP
  2. KatieK

    KatieK Active Member

    Messages:
    116
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #2
    I would accomplish this by using focus().
     
    KatieK, Feb 18, 2008 IP
  3. Dimension

    Dimension Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i spend ages trying to find some sort of tutorial on how to do this. could anyone give me a link to help me?
     
    Dimension, Feb 25, 2008 IP
  4. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Morishani, Feb 26, 2008 IP
  5. Dimension

    Dimension Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    this is not what im looking for.

    the left box should be a multiple dropdown and the left empty. i want to select items from the left box and add them to the right box.

    the reason i need it this way is because i need to select 4 items from a list and i dont want to have 4 dropdown boxes with the same information in each.
     
    Dimension, Feb 26, 2008 IP
  6. KatieK

    KatieK Active Member

    Messages:
    116
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Dimension, can you post a link to a page showing what you have so far?
     
    KatieK, Feb 26, 2008 IP
  7. stoli

    stoli Peon

    Messages:
    69
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you want to be able to select multiple items from a select list then you can just add the "multiple" attribute to the select element:
    <select size="3" multiple="multiple">
    <option value="option1">Option 1</option>
    <option value="option2">Option 2</option>
    <option value="option3">Option 3</option>
    <option value="option4">Option 4</option>
    <option value="option5">Option 5</option>
    </select>
    HTML:
    Press "Ctrl" and click to select multiple options in the list. Size is the number of visible items.
     
    stoli, Feb 28, 2008 IP
  8. Kylratix

    Kylratix Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Just add an onclick event handler for the first drop down box. Grab the highlighted value from there to determine what array of options you want to put in the second select box. Then (if you were using mootools)

    
    var secondSelect = $('secondSelect');
    secondSelect.empty(); // clears second
    for (var i = 0; i < myOptionArray.length; ++i)
    {
        secondSelect.adopt( new Element('option', {
               'value': myOptionArray[i].value
            })
            .setText(myOptionArray[i].text)
         );
    }
    
    Code (markup):
     
    Kylratix, Feb 28, 2008 IP