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
550
How to get the checked value from webdropdown
posted

Hi,

I m using WebDropDown with MultipleSelectionType="Checkbox" EnableClosingDropDownOnSelect="false"   DisplayMode="DropDownList" EnableMultipleSelection="true" ,

here i m  binding data from serverside(using c#) , how to get the value of checked checkbox values in javascript. below is my sample code, in the below code

if (e.target.checked) is giving error.


<ig:WebDropDown ID="cmbApplication" ClientEvents-SelectionChanged="CheckChanged" ClientEvents-DropDownOpened="wddcmbApplication_AfterDropDown" ClientEvents-DropDownClosed="wddcmbApplication_AfterCloseUp"
ClientEvents-DropDownClosing="wddcmbApplication_BeforeCloseUp" runat="server" Width="200px"
MultipleSelectionType="Checkbox" EnableClosingDropDownOnSelect="false" EnableViewState="false" DisplayMode="DropDownList" EnableMultipleSelection="true" >
</ig:WebDropDown>


function CheckChanged(e) {
debugger
var value="";
var wdd = $find("cmbApplication");
var wdd1 = ig_controls.cmbApplication;
for (var i = 0; i < wdd.get_items().getLength(); i++) {

if (e.target.checked) {
value+= wdd.get_items().getItem(i).get_text()+", ";
wdd.get_items().getItem(i).select(false);
}
else {
wdd.get_items().getItem(i).unselect(false);
}

}

wdd.set_currentValue(value,true);
wdd.closeDropDown();
}

Thanks

Ravi

Parents
  • 17590
    Offline posted

    Hello Ravi,

    Thank you for posting in the community.

    What I can suggest for achieveing your requirement is using get_selectedItems() method. This method retuns a collection of all the currently selected items that you could acces by index. For example if you are looking for the first selected item you could use the following code: $find("WebDropDown1").get_slectedItems()[0].

    In your case you could handle the SelectionChanged client side event and in this event to get all the selected items from the WebDropDown and resoectively get access to the selected elements text, value etc. For example:

    function WebDropDown1_SelectionChanged(sender, eventArgs)

    {

    var dropDown = ig_controls.WebDropDown1;

    var selectedItems = dropDown.get_selectedItems();

    var value;

    for (var i = 0; i < selectedItems.length; i++) {

    value += selectedItems[i].get_text() + " ,";

    }

    alert(value);

    }

    I also made a small sample illustrating my suggestion and I am attaching it for your reference.

    I hope you find this information helpful.

    Please let me know if you need any further assistance with this matter.

    WDDGetSelectedItems.zip
Reply Children