I want to change selectionIndex on button click in jquery
My Code is
<asp:DropDownList runat="server" ID="d">
</asp:DropDownList>
What I have tried:
$(document).ready(function () {
try {
$('#<%=d.ClientID %>').on('change', function () {
try {
var ban = $('#<%=d.ClientID %>').val();
alert(ban);
}
catch (e) {
}
});
a();
}
catch (e) {
alert(e);
}
});
function a() {
try
{ $("[id*=d]").empty();
var _select = $("<select>");
_select.append($("<option value='0'>Select One</option>"));
_select.append($("<option value='1'>One</option>"));
_select.append($("<option value='2'>Two</option>"));
$("[id*=d]").append(_select.html());
$('#<%=d.ClientID %>').val('1');
$('#<%=d.ClientID %>').change();
}
catch(e)
{
alert(e);
}
}
It is not working.
If I add statically option to
<option value='0'>Select One</option>
<option value='1'>One</option>
<option value='2'>Two</option>
and modify a() function
function a() {
try
{
$('#<%=d.ClientID %>').val('1');
$('#<%=d.ClientID %>').change();
}
catch(e)
{
alert(e);
}
}
Now it is working