简体   繁体   中英

pass the id of textbox to dropdownliast onchange event in javascript

I have a dropdownlist defined:

         <asp:DropDownList Width="300px" ID="PlaceHoldersDropDownList" runat="server"
                AppendDataBoundItems="True" TabIndex="3" onchange="PasteTextInEditor 
                                    (this.options[this.selectedIndex].value), '<%= 
                                     SubjectTextBox.ClientID %>'"   >

So, I pass the selected text and a textbox ID to a javascript function. The text box is defined as:

       <asp:TextBox Width="660px" ID="SubjectTextBox" Text='<%# Bind( "Subject") %>' 
           runat="server" TabIndex="4" MaxLength="100">
        </asp:TextBox>

So, in script function, when i put alert like this :

            alert(text);    //shows selected value
            alert(editor); // shows undefined

So editor value is turning up undefined. So, can you please let me know the mistake I've been doing. I would like to save that value selected from dropdown into textbox.Please help me fixing th eproblem. Thank You

It looks like your bracket is in the wrong place in your "onchange": you're only passing one parameter and not the client id.

But regardless, the ClientID is not going to be parsed here. Instead, I suggest you add your onclick in the code behind, either in your Page_Load or Page_PreRender:

PlaceHoldersDropDownList.Attributes.Add("onchange", "PasteTextInEditor(this.options[this.selectedIndex].value, '" + SubjectTextBox.ClientID + "');")

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM