I have this combobox and I need to populate a textbox with the selected combobox value on the clientside. What I have doesn't seem to be working. Am I doing this correctly?
<asp:ComboBox ID="cmbOutputRating" runat="server"
DropDownStyle="DropDown"
AutoCompleteMode="Suggest"
CaseSensitive="false"
RenderMode="Inline"
ItemInsertLocation="Append"
onchange="javascript:ddlChange();">
</asp:ComboBox>
Here is the textbox:
<asp:TextBox ID="txtOutputRating" runat="server"
CssClass="inputFieldSmall"
OnTextChanged="txtOutputRating_TextChanged"
AutoPostBack="True"
meta:resourcekey="txtOutputRatingResource1">
</asp:TextBox>
Here is the javascript:
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
function ddlChange()
{
var cmb = document.getElementById('<%=cmbOutputRating.ClientID %>');
var textBox = document.getElementById('<%= txtOutputRating.ClientID%>');
textBox.value = cmb.options[cmb.selectedIndex].value;
}
</script>
</asp:Content>
The combobox is rendered as an input so you would grab the value of it like so:
<script type="text/javascript">
function ddlChange()
{
var cmb = document.getElementById('<%=cmbOutputRating.ClientID %>');
var textBox = document.getElementById('<%= txtOutputRating.ClientID%>');
textBox.value = cmb.value;
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.