0

I'm trying to open/close a select dropdown content programmatically, but I can't figure out how to call "open" and "close" on the select

Here's an example: Fiddle

CODE

$(document).keyup(function(e){
    if(e.which >= 48 && e.which <= 57){
        $("#myselect").click();
        $("#keyOpen").empty().text(e.which);
    }else if(e.which >= 58 && e.which <= 90){
        $("#myselect").trigger("click");
        $("#keyClose").empty().text(e.which);
    }
});

if the key pressed is numeric (0-9), it should open, if the key pressed is a char (a-z), the select should close.

this set of char is just an example, I'd like to bind the open/close gesture to a keyboard input.

Any ideas?

Thanks in advance, best regards

BeNdErR
  • 17,471
  • 21
  • 72
  • 103

2 Answers2

7

Take a look to the documentation of the widget and use:

$("#myselect").selectmenu( "open" );
$("#myselect").selectmenu( "close" ); 

Also you have to add data-native-menu="false" to your markup as native element will not open.

Working demo here.

Jonathan Naguin
  • 14,526
  • 6
  • 46
  • 75
0

You can't open a standard SELECT box, you'll have to create your own select-like box and open that.

Louis Ricci
  • 20,804
  • 5
  • 48
  • 62