I have code below:
<select id="test">
<option value="a">aaa</option>
<option value="b">bbb</option>
</select>
<asp:Button ID="btnTest" runat="server" Text="Test it!" onclick="btnTest_Click" />
I need to get selected index not selected value on postback. How can I do this with asp.net? this is my code for filling the select html:
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("#<%=btnTest.ClientID %>").click(function(){
$.ajax(
{ url: "StateCity.asmx/ReferItems?id=" + getParameterByName('id'),
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST",
success: function(data) {
$("#test").empty();
$.each(data.d, function() {
$("#test").append($("<option></option>").val(this['Value']).html(this['Text']));
});
},
error: function() { alert("Error"); }
})
})
</script>