Alert selecting items

4 posts, 0 answers
  1. Shahi
    Shahi avatar
    17 posts
    Member since:
    Apr 2013

    Posted 15 May 2013 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 May 2013 Link to this post

    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.
  3. Shahi
    Shahi avatar
    17 posts
    Member since:
    Apr 2013

    Posted 15 May 2013 Link to this post

    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.
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 May 2013 Link to this post

    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.
Back to Top