)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

Is it possible to differentiate the user selection or programmatically selection of the items in the DropDownList?

Platform: jQuery |
Control: ejDropDownList |
Published Date: July 29, 2016 |
Last Revised Date: May 10, 2019

Solution

Yes, It’s possible to differentiate the selection of items in DropDownList using “isInteraction” argument in the select event of DropDownList.

 

If the value of “isInteraction” is true , then the item has been selected by user interaction. Otherwise it has been selected by properties or methods such as “selectItemByText”, “selectItemByValueor “selectItemByIndicesin the DropDownList.

 

Initialize the DropDownList as follows

HTML

<div class="ctrllabel">Select a car</div>

        <input type="text" id="selectCar" />

        <div id="carsList">

            <ul>

                <li>Audi A4</li>

                <li>Audi A5</li>

                <li>Audi A6</li>

                <li>Audi A7</li>

                <li>Audi A8</li>

            </ul>

 

        </div>

        <button id="button21">Select</button>

var target;

        $(function () {

            target = $('#selectCar').ejDropDownList({

                targetID: "carsList",

                width: "150px",

                select: "onSelect"

            }).data("ejDropDownList");

 

            $("#button21").ejButton({

                showRoundedCorner: true,

                size: "mini",

                click: "onClick"

            });

        });

 

Upon selecting the items in the DropDownList, the client side event “select” will be triggered, in that check whether the value of isInteraction argument is true or not.  If the value is true, the item has been selected by user(selected through the mouse hover).

 

Javascript

function onSelect(args) {

 

            if (args.isInteraction)

                alert("The item " + args.value + " has been selected by user");

            else

                alert("The item " + args.value + " has been selected programmatically");

        }

 

        function onClick(args) {

            target.selectItemByValue("Audi A7");

        }

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon