troubleshooting Question

How to select Listbox item via Javascript Jquery

Avatar of adworldmedia
adworldmediaFlag for United States of America asked on
2 Comments1 Solution2340 ViewsLast Modified:
I have a ListBox control on a page, that has nothing selected.

I will display a generated TABLE that includes a Javascript ONCLICK event to call a JS function to select that item.

Generated onclick event for the row:
onclick=\"addListbox('" + row.Channel_ID.ToString() + "')"

the JS:
<script type="text/javascript">
    function addListbox(selectedItem)
        $("#ddChannels option[value='" + selectedItem + "']").attr("selected", true);

Just for reference, the listbox:

<asp:ListBox ID="ddChannels" runat="server" CssClass="chzn-select" SelectionMode="Multiple"></asp:ListBox>

This ListBox is populated by the code behind...

But it doesn't seem to be working.
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros