check items in order

2 posts, 1 answers
  1. Alan
    Alan avatar
    10 posts
    Member since:
    May 2012

    Posted 06 Jul 2012 Link to this post

    Hi,

    How can I have a combobox which us allow to check items only in order. ie it should not allow to check 2nd item if 1st is not checked.

    Thanks
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Jul 2012 Link to this post

    Hi Alan,

    Try the following Javascript to achieve your scenario.

    JS:
    <script type="text/javascript">
       function OnClientItemChecking(sender, args)
        {
          var index = args.get_item().get_index();
          if (index != 0)
          {
            if (!sender.get_items().getItem(index).get_checked())
            {
              if (!sender.get_items().getItem(index - 1).get_checked())
              {
               args.set_cancel(true);
              }
            }
            else
            {
             for (var i = index + 1; i < sender.get_items().get_count(); i++)
              {
               sender.get_items().getItem(i).set_checked(false);
              }
            }
          }
        }
    </script>

    Thanks,
    Shinu.
Back to Top