Adding option elements to select on focus

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Josh C.

    Adding option elements to select on focus

    I am attempting to dynamically add an option to a select box when the
    box is selected (click or focus). This works fine using Firefox by
    either creating a new element and appending it to the SELECT's
    children, or by creating a new Option() and setting it to the
    select.options array.

    My problem is in IE whenever it adds the element the select box does
    not drop down. For instance if I have my code run onFocus when the
    select box is clicked the option is added and the box does not drop
    down. If I click it a second time while it still has focus it will
    display the new value.

    Is there a trick or work around to have IE handle this the same as FF?

    thanks,
    jc
  • SAM

    #2
    Re: Adding option elements to select on focus

    Josh C. a écrit :
    I am attempting to dynamically add an option to a select box when the
    box is selected (click or focus). This works fine using Firefox by
    either creating a new element and appending it to the SELECT's
    children, or by creating a new Option() and setting it to the
    select.options array.
    >
    My problem is in IE whenever it adds the element the select box does
    not drop down. For instance if I have my code run onFocus when the
    select box is clicked the option is added and the box does not drop
    down. If I click it a second time while it still has focus it will
    display the new value.
    >
    Is there a trick or work around to have IE handle this the same as FF?
    IE doesn't leave focus so easily

    add : this.options.se lectedIndex = this.options.le ngth-1;

    try also : onmousedown (... ? ! ! ? )

    <script type="text/javascript">
    function extend(quoi) {
    quoi = quoi.elements['ici'];
    quoi.length=0;
    for(var i=0; i<20; i++)
    quoi.options[quoi.length] = new Option(i, i);
    quoi.options.se lectedIndex=quo i.length-1;
    }
    </script>
    <form action="#" onsubmit="retur n confirm('sure?' );">
    <p><select name='ici' onfocus="extend (this.form);">
    <option>test</option>
    </select>
    </form>

    My browsers (IE Mac Fx ...) works all the same : while you don't click
    outside the select, focus stay on it and the function do not more fire.

    Comment

    Working...