0

I know I can focus and select an HTML selectbox drop-down with jquery:

<script>
    $('#otherbox').on('change', function() {
        $("#selbox").focus();
        $("#selbox").select();
    });
</script>

But this only focuses the selectbox but it doesn't open it, I still have to click on the select-element with the mouse to open it.

How can I automatically open the selectbox by another event?

rubo77
  • 19,527
  • 31
  • 134
  • 226

1 Answers1

0

There are two ways to do it:

  • you can either try to use MouseEvent to simulate the mousedown (https://developer.mozilla.org/en/docs/Web/API/MouseEvent + check the links in the comments)

  • or you can create an invisible div with select's options duplicated in it right under the select itself and upon a click event just make that div visible, thus emulating an open dropdown.

dekkard
  • 6,121
  • 1
  • 16
  • 26