Sta funzionando bene con me.
Ho il seguente codice 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>
E il seguente JavaScript:
function GetSelectedItem(el)
{
var e = document.getElementById(el);
var strSel = "The Value is: " + e.options[e.selectedIndex].value + " and text is: " + e.options[e.selectedIndex].text;
alert(strSel);
}
Vedi che si sta utilizzando il diritto id. Se lo si utilizza con ASP.NET, l'ID cambia quando viene eseguito il rendering.
cosa ottieni in sv? – Kangkan
È possibile incollare il contenuto html insieme alla funzione javascript utilizzata – AmGates
Vedere anche: http: // stackoverflow.it/questions/1085801/how-to-get-selected-value-of-dropdownlist-using-javascript – Kangkan