Saturday, October 6, 2012

Javascript: getting selected item


Html:

<select id="estadosiniciales">
                    <option value ="sydney">Sydney</option>
                    <option value ="melbourne">Melbourne</option>
                    <option value ="cromwell" selected>Cromwell</option>
                    <option value ="queenstown">Queenstown</option>
</select>

Javascript:


var selectIni = document.getElementById("estadosiniciales");      
alert(selectIni.options[selectIni.selectedIndex].text);


Resources:
http://www.java2s.com/Tutorial/JavaScript/0200__Form/Findtheselectedoption.htm

No comments: