How to get selected value from Dropdown list in javascript -



How to get selected value from Dropdown list in javascript -

how can selected value drop downwards list using javascript? have tried next not work.

var sel = document.getelementbyid('select1'); var sv = sel.options[sel.selectedindex].value; alert(sv);

it working fine me.

i have next html:

<div> <select id="select1"> <option value="1">test1</option> <option value="2" selected="selected">test2</option> <option value="3">test3</option> </select> <br/> <button onclick="getselecteditem('select1');">get selected item</button> </div>

and next javascript:

function getselecteditem(el) { var e = document.getelementbyid(el); var strsel = "the value is: " + e.options[e.selectedindex].value + " , text is: " + e.options[e.selectedindex].text; alert(strsel); }

see using right id. in case using asp.net, id changes when rendered.

javascript

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -