How do I get the array of selected values of a given dropdown?

Hello

Is there a method to get the array of selected values? I mean, without using v-model.

Thanks!


1 Reply 1 reply marked as answer

KP Kokila Poovendran Syncfusion Team July 31, 2023 05:31 PM UTC

Hi Ernesto,


Thank you for reaching out to us.


To obtain the array of selected values from a given dropdown, you can access it through the Multiselect instance. By obtaining the current value of the Multiselect component, you can easily access the selected values.


Below is a sample code snippet that demonstrates how to achieve this:


<button v-on:click="handleButtonClick">Click me!</button>

 

 

methods: {

        handleButtonClick() {

            var msObject = document.getElementById("multiselect").ej2_instances[0];

            var arrayOfvalues = msObject.value;

            // You can get the array of selected values in "arrayOfvalues" variable

        }

    }


By using document.getElementById("multiselect").ej2_instances[0], you can get the Multiselect instance, and then msObject.value provides you with the array of selected values. You can further process this array according to your requirements.


Attachment: dropdown_63dcd5ce.zip

Marked as answer
Loader.
Up arrow icon