Dynamically populate dropdown list with jquery

Dynamically populate dropdown list with jquery

Hello

I'm using SharePoint 2010 and have an issue with ASP dropdown list. Based on user's AD groups, some users should have anywhere from 2 to 4 items in the drop-down list and it could be different combination of items for each user. Then the value that user choses from drop-down is passed to multiple web parts on the page. I'd like to setup that dropdown list dynamically, using jquery. I already have the code to get the items based on the AD groups. I'm new to jquery and not quite sure how to assign the text values and actual values to the drop-down list. Please advise. Currently I have DropDown list filled with bogus items, that I would need to replace with actual text and values. I guess if there are only 2 items, I'd have to hide 3d. Or I can have 2 by default and need a way to add 3d and 4th if needed. Thank you!

  1. <asp:DropDownList runat="server" id="DropDownList1" AutoPostBack="True">
            <asp:ListItem value="06">Fac1</asp:ListItem>
            <asp:ListItem value ="07">Fac2</asp:ListItem>
            <asp:ListItem value="08">Fac3</asp:ListItem>
           </asp:DropDownList>
  2. This code didn't do what I wanted. Not sure how to replace each option with correct data
  3.  $("input[id$=DropDownList1]").val("actual number");
    $("input[id$=DropDownList1]").text("actual name");
  4. P.S. Using <script language="javascript" type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.0.min.js"> </script>