-1
 <select id="myList" onchange="favBrowser()">

 <option> var x</option>
 <option> var y</option>  


</select>

<script>
   var x="google";   var y="firefox";
 </script>

my question is , how to take the option's values from javascript

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48
  • 1
    duplicate of http://stackoverflow.com/questions/9895082/javascript-populate-drop-down-list-with-array – Tomer W Jul 15 '13 at 08:23

3 Answers3

0

You can get it by writing

function favBrowser(){
 var sel = document.getElementById("myList");
 var value =sel.options[sel.selectedIndex].value;  
 window.alert(value);
   }
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

You need to supply more information about what it is you really want to do. If what you want is to take the selected value, then take a look at this question

Get selected value in dropdown list using JavaScript?

Community
  • 1
  • 1
Karsten
  • 83
  • 2
  • 13
0

i think he ment he want to fill the options by Script

this can be done by

<select id="myDropdown">

</select>

<script type="text/javascript">
    function fillDropDown() {
        var ddl = document.getElementById('myDropdown');

        for (var i = 1; i < 50; i++) {
            var myNewOption = new Option();
            myNewOption.value = i;
            myNewOption.text = "my " + i.toString() + " option...";
            ddl.options.add(myNewOption);
        }
    }

    fillDropDown();
</script>

Cheers.

Tomer W
  • 3,395
  • 2
  • 29
  • 44