Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
100
WebDropDown - SelectedItems from Javascript not working
posted
Hi,

 

I am having trouble figuring out how to access the selected items property of a webdropdown through javascript when multipleselection is enabled.  The control is declared as:

 

<ig:WebDropDown ID="cmbYears" runat="server" Width="300px" TextField="Value"
MultipleSelectionType="Checkbox" EnableClosingDropDownOnSelect="false"
EnableMultipleSelection="True">
<Items>
<ig:DropDownItem Key="2008" Selected="False" Text="2008" Value="2008" />
<ig:DropDownItem Key="2009" Selected="False" Text="2009" Value="2009" />
<ig:DropDownItem Key="2010" Selected="False" Text="2010" Value="2010" />
<ig:DropDownItem Key="2011" Selected="True" Text="2011" Value="2011" />
<ig:DropDownItem Key="2012" Selected="False" Text="2012" Value="2012" />
</Items>
</ig:WebDropDown>

 

I am trying to access the selected items from javascript, the code in question is:

 

<script type="text/javascript">
function load() {
var year = document.getElementById('<%=cmbYears.ClientID%>').get_selectedItems();
}
</script>

 

I found this forum post: http://blogs.infragistics.com/forums/p/37328/216609.aspx#216609, but it does not seem to be working.

 

I have tried many variations of selectedItems. All of these give me a: "Object doesn't support this property or method"

 

getElementById( ... ).get_selectedItems[0];
getElementById( ... ).get_selectedItems;
getElementById( ... ).selectedItems[0];
getElementById( ... ).selectedItems;

 

getElementById( ... ).get_selectedItems()[0];
getElementById( ... ).get_selectedItems();
getElementById( ... ).selectedItems()[0];
getElementById( ... ).selectedItems();

 

This one returns an "undefined":

 

getElementById( ... ).value

 

I have been unable to figure out what the problem is.  Any help would be much appreciated.

 

Thank you in advance, please let me know if you need more information.

 

Using Infragistics Ultimate version 11.1 ASP.NET controls.
  • 8160
    Verified Answer
    posted

    Hello snaidich,

    you will have to use $find(), because document.getElementById returns html element, not an object. The code should be:

            function load() {
                var wdd = $find('<%=cmbYears.ClientID %>');
                wdd.get_selectedItems();
            }

    This will return collection with all selected items.

    Please let me know if you need further assistance