0

I am able to add value to textbox in User control using jQuery. Below is my code:

$("input[id*=txtApproverEmail]").val("EmailAddress");

How to add or append value to listbox in user control using jQuery or javascript?

Below is my user control:

<tr>
    <td>Select Approver:</td>
    <td>
        <asp:TextBox ID="txtApproverEmail" runat="server" CssClass="text ui-widget-content ui-corner-all" ReadOnly="true"></asp:TextBox>
        <img id="imgCOApproverEmail" src="../Images/Binoculars.png" />
    </td>
</tr>
<tr>
    <td>Carbon Copy To:</td>
    <td>
        <asp:ListBox ID="lstCCTo" runat="server" CssClass="text ui-widget-content ui-corner-all" Width="310px"></asp:ListBox>
        <img id="imgCOApproverEmailCCTo" src="../Images/Binoculars.png" />
    </td>
</tr>

1 Answer 1

1

Try this:

$('select').append('<option>New value</option>');

Or

$('select[id*=lstCCTo]').append('<option>New value</option>');
Sign up to request clarification or add additional context in comments.

3 Comments

It is not working. Unable to detect the usercontrol listbox ID like this
the ID of any ASPX components change after page renderization. See stackoverflow.com/questions/23768106/…
If you have only one listbox then you can do $('select').append('<option>New value</option>'); or try $('select[id*=lstCCTo]').append('<option>New value</option>');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.