jquery - Select2 open dropdown on focus text input -


i have form 1 text input , 1 select2 element (version 4.0.0). want when focus on text input, select2 open.

here’s i’ve tried :

<select list="useraccountsmap.values" listkey="accountno" listvalue="accountno"/> <input id="destinationaccount" type="text" name="destinationaccount">  <script type="text/javascript">  ('select').each(function( index ) {          $(this).select2();      } });  $("#destinationaccount").focus(function () {        $("select").trigger('select2:open'); });  </script> 

but not work. see fiddle here: http://jsfiddle.net/hatamikhah/73wypp1w/1/

i don't understand problem is.

they have explained example how open drop-down option.

documentation url: https://select2.github.io/examples.html , please check programmatic access section.

html part:

<select id="e1">   <option value="volvo">volvo</option>   <option value="saab">saab</option>   <option value="mercedes">mercedes</option>   <option value="audi">audi</option> </select>  <br> <br> <input type="text" id="nameid" name="firstname"> 

jquery part:

$("#e1").select2();  // change event $("input").on("change", function () {     $("#e1").select2("open"); });  // focus event  $( "input" ).focus(function() {   $("#e1").select2("open"); }); 

try example onchange event: http://jsfiddle.net/mananpatel/73wypp1w/5/

let me know if need :)


Comments