如何在javascript中设置textBox.Text = radCombo.Text

时间:2014-12-13 06:53:43

标签: javascript c# asp.net vb.net telerik

我的表单中有<telerik:RadComboBox><asp:TextBox>。我想在comboBox的textBox.Text=radCombo.Text上的客户端显示Textchange event。我使用的代码为:

<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <telerik:RadComboBox ID="cboSample" EnableLoadOnDemand="true" runat="server" Skin="WebBlue" Text ="sample" OnClientKeyPressing  ="func()">
                  </telerik:RadComboBox>
        <asp:TextBox runat="server" ID="txtSample"></asp:TextBox>
    </div>
    </form>
    <script type="text/javascript">
        function func() {
            var cbo = document.getElementById("cboSample");
            document.getElementById("txtSample").Text = cbo.getAttribute("Text");                               
        }
    </script>
</body>

我做错了什么?我怎样才能实现目标

1 个答案:

答案 0 :(得分:0)

尝试以下解决方案

 <telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientDropDownClosing="OnClientDropDownClosing1">
        <Items>
            <telerik:RadComboBoxItem Text="Invoice" runat="server" Selected="true" />
            <telerik:RadComboBoxItem Text="Quote" runat="server" />
        </Items>
    </telerik:RadComboBox>
    <asp:Label ID="Label1" runat="server" Text="Invoice">
    </asp:Label>



    <script type="text/javascript">  
     function OnClientDropDownClosing1(sender, args) {
            var label = document.getElementById("Label1");
            label.textContent = sender._selectedItem._text;
        }
    </script>