Forum Moderators: open
I've got a drop down which needs to be populated dynamically when the user sets the focus on it:
<select id='foo'>
<option value='0'>All</option>
</select>
When the use selects this element, it fetches some data from the server to get the valid options (based on other fields on the page). It then populates the select with those options. The problem, though, is that when you have a select element that is dropped down (showing the options) and you append options to that select element, IE will close the drop down. I need to find a way to keep that drop down list open, or tell IE to re-open it when it's done adding options.
Here's a code example:
window.onload = function () {
var foo = document.getElementById('foo');
foo.onfocus = function () {
var op = document.createElement('option');
op.setAttribute('value','value');
op.appendChild(document.createTextNode('text'));
this.appendChild(op);
};
};
Note, my real world case is using event listeners, but for simplicity of this example, I'm just setting the event handlers instead.
Anyone have any ideas?
I think the approach I'm going to take is a sort of pseudo select element. That is, I'll create an input, when that item gets focus I will display a (previously hidden) select box with a fixed size on top of that input, and onblur of that select I will populate the value in the text field and hide the select again. At least, that's what I'm thinking.