This is a migrated thread and some comments may be shown as answers.

Alert selecting items

3 Answers 77 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Shahi
Top achievements
Rank 1
Shahi asked on 15 May 2013, 05:34 AM
Hi,

I got a requirement there is a radcombobox and the user need to check atleast three items from it. If the user does not check three show alert that he need to select three or more items and prevent closing the dropdown.

Please help soon
Shahi

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 May 2013, 05:56 AM
Hi Shahi,

Try the following java script to achieve your scenario.
JS:
 //to show alert while checking the items
function OnClientItemChecked(sender, args)
{
     var count = sender.get_checkedItems().length;
     if (count < 3)
     {
      alert("Select 3 or more items!");
     }
}
 // to prevent closing if 3 items are not selected
function OnClientDropDownClosing(sender, args)
 {
    if(sender.get_checkedItems().length>=3)
    {
        args.set_cancel(false);
    }
    else
    {
        args.set_cancel(true);
    }
}

Thanks,
Princy.
0
Shahi
Top achievements
Rank 1
answered on 15 May 2013, 06:46 AM
Thanks but it didnt work as i expected. Its alerting each and every time which is not needed for me. The alert should come only if one or two items are checked and that too on closing. User should be able to close if nothing is checked and no alert should come that time. Please reply soon.
0
Princy
Top achievements
Rank 2
answered on 15 May 2013, 07:55 AM
Hi,
Try the following js.
JS:
function OnClientDropDownClosing(sender, args)
 {
   if(sender.get_checkedItems().length==0)
   {
        args.set_cancel(false);
   }
    else if (sender.get_checkedItems().length <3)
    {
        alert("Select 3 or more items!");
        args.set_cancel(true);
    }
 }
Note: Normally dropdown will close when we click on outside also.

Thanks,
Princy.
Tags
ComboBox
Asked by
Shahi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shahi
Top achievements
Rank 1
Share this question
or