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
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); }
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.
Hi Vasya,
thanks for the reply, here i have one more doubt , how to set a check box property as checked using js code.
for example i have "select All" check box as first followed by another two values and check boxes , if i select "select All" i want to manuall set checked for remaining checkboxes. below is the sample code i m trying to achive. suggest me how can i set a check box checked.
var wdd = $find("cmbApplication");
var getItemscount = wdd.get_items().get_length();
for (var i = 0; i < wdd.get_items().getLength() ; i++) {
var selectedItem = $find("cmbApplication").get_items().get_item(i).get_text();
if (selectedItem == "All") {
//Here how to set all checkboxs checked
value = "AllApplications";
wdd.set_currentValue(value, true);
wdd.closeDropDown();
else{
value = "";
thanks
Can you please respond to my doubts mentioned in above post.
I'm attaching a sample of the desired behavior.
Regards,
Tsanna
Please feel free to contact us if you need any further assistance with this matter.