locked
selector dynamic add options always with one duplicate option

    Question

  • var selector = document.getElementById("selectorId");
                              
                    for (var i = 1; i <= 4; i++) {
    
                        selector.add(new Option(i, i));
                    }

    I add options dynamic using above code, and I expect 1,2,3,4 in the options, but there is always a duplicate option in the last:

    Is this a bug? 


    • Edited by Forzas Friday, September 6, 2013 12:52 PM
    Friday, September 6, 2013 12:51 PM

Answers

  • Hi Forzas,

    I tried that, works fine. Try to new a project and testing the code you will find everything should be ok.

    Or you could repro the problem with a demo, I'd like to help you with the problem you meet.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 9, 2013 1:02 AM
    Moderator