I'm trying to get the selected text (not value) from a DropDownList into a TextBox. The DropDownList is located within the EditITemTemplate of my FormView control, but the TextBox is not.
Here is the js I am trying to use:
<script type="text/javascript">
function GetDdlText() {
var fvmode = ('<%=fvPhaudDets.CurrentMode.ToString()%>');
if (fvmode == "Edit") {
var ddl = document.getElementById('<%=fvPhaudDets.FindControl("QOpClsCallDdl")%>');
var txt = document.getElementById("txtbox");
var selectedText = ddl.options[ddl.selectedIndex].Value;
txt.Text = selectedText;
txt.focus();
}
}
</script>
Here is the OnSelectedIndexChanged event where I'm calling the js:
protected void QOpClsCallTextBox_OnSelectedIndexChanged(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "TheTxt", "GetDdlText();", true);
}
So anytime that a new value is selected in the DropDownList, the selected text should populate the TextBox, but no values are going into the TextBox. What am I missing, or what do I need to change to capture the selected value?