dynamically select drop down

Discussion in 'JavaScript' started by khu84, Mar 17, 2009.

  1. #1
    I am using a form and on different actions I am filling the form fields with data on different actions just calling em by their ID.

    Now for drop down, how will select a value from the options via javascript?
     
    khu84, Mar 17, 2009 IP
  2. slash197

    slash197 Greenhorn

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    it's very simple.

    you have the select:
    <select name="myselect">
    <option value="1">option1</option>
    <option value="2">option2</option>
    </select>

    and from js you can select an option like this:

    form.myselect.value = "1";
     
    slash197, Mar 18, 2009 IP
  3. RoyalFlushed

    RoyalFlushed Peon

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey Slash, i tought it was more something like this :

    myselect.selectedIndex = 1;

    I don't think u can change the list bij just setting the value property.

    good luck!
     
    RoyalFlushed, Mar 20, 2009 IP