patel
patel

Reputation: 1623

how to reset dropdown selected index serverside value from javascript?

problem is I have a date text box and a shifts drop down. When I select a date and shift I get the list of employees. dropdown has a onSelectedIndexChanged event, so employee list will be populate only if we change shifts. So for date chage I have added ajavascript to reset shift dropdown to 0 index. therefore every time when you change the date you have to select the shift too and the selectindex change event will be fired.BUT the problem is when I reset shifts dropdown from javascript it is done only in client side not in server side.So if I select dropdownt to the previous value it doesn't fire the change event but for other values it works fine.

<asp:TextBox ID="txtSelectDate" runat="server" CssClass="inputAddRes" onchange="javascript:return ResetShifts();"></asp:TextBox>  

<asp:DropDownList ID="ddlShifts" AutoPostBack="true" OnSelectedIndexChanged="ddlShifts_SelectedIndexChanged"                                     runat="server" >
<asp:ListItem Text="Morning" Value="1"/>
<asp:ListItem Text="Evening" Value="2"/>
<asp:ListItem Text="Night" Value="3"/>
</asp:DropDownList>

function ResetShifts() {
        document.getElementById('<%= ddlShifts.ClientID %>').selectedIndex = 0;
        }

Upvotes: 0

Views: 2509

Answers (1)

David
David

Reputation: 8670

You could just call the select onchange event manually

 document.getElementById('<%= ddlShifts.ClientID %>').onchange();

Upvotes: 0

Related Questions