我有这个组合框,我需要在客户端用选定的组合框值填充文本框。我所拥有的似乎不起作用。我这样做正确吗?

<asp:ComboBox ID="cmbOutputRating" runat="server"
DropDownStyle="DropDown"
AutoCompleteMode="Suggest"
CaseSensitive="false"
RenderMode="Inline"
ItemInsertLocation="Append"
onchange="javascript:ddlChange();">
</asp:ComboBox>


这是文本框:

<asp:TextBox ID="txtOutputRating" runat="server"
CssClass="inputFieldSmall"
OnTextChanged="txtOutputRating_TextChanged"
AutoPostBack="True"
meta:resourcekey="txtOutputRatingResource1">
</asp:TextBox>


这是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>

最佳答案

组合框作为输入呈现,因此您可以像这样获取其值:

<script type="text/javascript">
function ddlChange()
{
var cmb = document.getElementById('<%=cmbOutputRating.ClientID %>');
var textBox = document.getElementById('<%= txtOutputRating.ClientID%>');
textBox.value = cmb.value;
}
</script>

09-28 13:21