Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: Christoph Becker Newsgroups: comp.lang.javascript Subject: Re: Who's eaten my apple and why? Date: Thu, 27 Sep 2012 01:35:17 +0200 Organization: Aioe.org NNTP Server Lines: 39 Message-ID: References: <37c94a7b-70f8-47f5-b5b8-2a1b3350de43@u19g2000yqo.googlegroups.com> NNTP-Posting-Host: QGGboTlrZLSM0JOcCcbD0Q.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.javascript:16160 justaguy wrote: > function dSelect() { > var sel = document.getElementById('mySel'); > var o = document.createElement('option'); > > o.value="a"; > o.text="apple"; > sel.options.add(o); > alert(sel.length); > > o.value="ora"; > o.text="orange"; > sel.options.add(o); > alert(sel.length); > } Your're adding the *same* object to the HTMLSelectElement twice. What's happening is explained in the specs (). If you want to add two "options", you have to create two distinct HTMLOptionElement objects: function dSelect() { var sel = document.getElementById('mySel'); var o = document.createElement('option'); o.value="a"; o.text="apple"; sel.options.add(o); alert(sel.length); o = document.createElement('option'); o.value="ora"; o.text="orange"; sel.options.add(o); alert(sel.length); } -- Christoph M. Becker