I have a page which contains multiple HTML select
dropdowns, and requires population onclick
of the element. This population is done using an AJAX call in the click event listener of the select
elements.
The reason for this is that performance and load are very crucial, and therefore they cannot be populated on page load.
Also, the design must use the native HTML select
element.
I have created a jsFiddle demo to show the issue. When you click on the select
the items are populated, and the width of the select
increases as a result.
However the select
only displays the initial option (prior to AJAX population).
------ View Demo ------
Demo uses setTimeout()
of 50 milliseconds to emulate an AJAX response time.
How can I get this to populate onclick
, and display correctly?
Is there a way of opening the select
on callback of the popualation response?
EDIT: Alternatively, is there a jQuery plugin dropdown, which uses the browser's native theme for styling?
What I've tried so far
- Populating the
select
on hover, however a quick user can open theselect
before the options have loaded. Also, if a user was to scroll all the way down the page, and over everyselect
, this would cause a lot of unnecessary AJAX calls. - Changing the event listener to
focus
instead ofclick
(as @AndyPerlitch suggested). However, this wouldn't work if the AJAX request took only 50 milliseconds to respond. (See Demo) - Changing the event listener to
mousedown
has the same effect asfocus
UPDATE: This is not an issue in FireFox. select
opens, then loads new items and displays them, all while in an open state.