Raghav
Raghav

Reputation: 3058

dropdown value changed by javascript is not coming in codebehind

I have a dropdown list whose value is changed based on other controls in the UI using javascript.

I used the following code to change the dropdown list, document.getElementById("ddlchkStsID").options[2].selected = true; document.getElementById("ddlchkStsID").value = "3";

But in the code-behind, the ddlchkStsID.SelectedValue is still coming as first option's value.

This the control in aspx page.

<asp:DropDownList ID="ddlchkStsID"  runat="server" TabIndex="10"  CssClass="meta">
 <asp:ListItem Text="TBD" Value="1" />
 <asp:ListItem Text="Yes" Value="2" />
 <asp:ListItem Text="No" Value="3" />
</asp:DropDownList>

Could someone help me how to get the changed value in the code-behind.

thanks in advance :)

Upvotes: 0

Views: 1106

Answers (1)

James Johnson
James Johnson

Reputation: 46047

Since the control is running at the server, you should be referencing the control using the ClientID, like this:

document.getElementById("<%=ddlchkStsID.ClientID%>").options[2].selected = true;

Is your JavaScript code actually working?

Upvotes: 2

Related Questions