I need to open the Chosen dropdown via JavaScript so users do not have to click on the select to show it, how can this be done?
Chosen is a JavaScript plugin that makes select boxes user-friendly. It is currently available in both jQuery and Prototype flavors. select, multiselect, dropdown, form.
Normally, to work with jQuery, we just need to link only one file but to work with the chosen plugin we need to link two files one is JavaScript and another is CSS. Finally, we take some select options and the multiple words that comes with the chosen plugin so that we can select multiple items at a single time.
You can open a chosen select box via JS by doing:
$('#<id-of-your-select>_chzn').trigger('mousedown');
where <id-of-your-select>
is the id of your <select>
element.
For ex: if your <select>
element is like <select id="foo" ...>
, then the code above will become:
$('#foo_chzn').trigger('mousedown');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With