Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Chosen via JavaScript?

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?

like image 469
Tzvi Avatar asked Jul 19 '12 09:07

Tzvi


People also ask

What is chosen js?

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.

How use jQuery chosen?

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.


1 Answers

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');
like image 152
techfoobar Avatar answered Sep 29 '22 20:09

techfoobar