0

i want to get the selected option from select box.I have this code:

<select id="sel">
<option selected>Seciniz</option>
    <%for(int i=1;i<k+1;i++){kullancounter++; %>
<option class="up"><%=ka[i] %></option>
    <%} %>
</select>
<input type="button" onclick="katsec()" value="Ekle">
               <script>
    function katsec(){
        alert('asd');
        var a=document.getElementById('sel').value;
        alert(a);
        document.getElementById('tak').innerHTML=a;
    }
        </script>

but it opens alert but there is nothing in alert.What should i do?Thanks

1 Answers1

0

Some browsers - namely, Internet Explorer - doesn't handle the value property of <select>s correctly. There's a workaround that work for every browser, though:

function katsec(){
    var sel = document.getElementById('sel'),
        idx = sel.selectedIndex,
        val = idx > -1 ? sel.options[sel].text : '';
    alert(val);
    document.getElementById('tak').innerHTML = val;
}
MaxArt
  • 22,200
  • 10
  • 82
  • 81