How to get selected value from Dropdown list in JavaScript

前端 未结 6 957
無奈伤痛
無奈伤痛 2020-12-28 16:17

How can you get the selected value from drop down list using JavaScript? I have tried the following but it does not work.

var sel = document.getElementById(\         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 16:37

    Hope it's working for you

     function GetSelectedItem()
     {
         var index = document.getElementById(select1).selectedIndex;
    
         alert("value =" + document.getElementById(select1).value); // show selected value
         alert("text =" + document.getElementById(select1).options[index].text); // show selected text 
     }
    

提交回复
热议问题