Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16164

Re: Who's eaten my apple and why?

From Gene Wirchenko <genew@ocis.net>
Newsgroups comp.lang.javascript
Subject Re: Who's eaten my apple and why?
Date 2012-09-26 17:59 -0700
Organization A noiseless patient Spider
Message-ID <f097689vq8t2i4d344qhsse20dg9jephgj@4ax.com> (permalink)
References <37c94a7b-70f8-47f5-b5b8-2a1b3350de43@u19g2000yqo.googlegroups.com> <k403fb$o5g$1@speranza.aioe.org>

Show all headers | View raw


On Thu, 27 Sep 2012 01:35:17 +0200, Christoph Becker
<cmbecker69@gmx.de> wrote:

>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

     Aren't the values simply taken?  If I set o to null after both
adds, it does not affect the select options so it presumably is not
referring to o after it is used to add an option.

>happening is explained in the specs
>(<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-94282980>).  If you
>want to add two "options", you have to create two distinct
>HTMLOptionElement objects:

      Where is it explained, please?  I have looked at the whole
section of select options, and I can not see it.

> 	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);
> 	}

     Yes, this works, but I do not understand why a second element
needs to be created.

Sincerely,

Gene Wirchenko

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Who's eaten my apple and why? justaguy <lichunshen84@gmail.com> - 2012-09-26 14:43 -0700
  Re: Who's eaten my apple and why? Christoph Becker <cmbecker69@gmx.de> - 2012-09-27 01:35 +0200
    Re: Who's eaten my apple and why? justaguy <lichunshen84@gmail.com> - 2012-09-26 17:46 -0700
      Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 03:51 +0200
        Re: Who's eaten my apple and why? justaguy <lichunshen84@gmail.com> - 2012-09-26 19:44 -0700
          Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 22:06 +0200
    Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-26 17:59 -0700
      Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 04:16 +0200
        Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-26 19:38 -0700
          Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 05:44 +0200
            Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-27 09:28 -0700
              Re: Who's eaten my apple and why? Tim Streater <timstreater@greenbee.net> - 2012-09-27 17:40 +0100
                Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-27 16:24 -0700
              Re: Who's eaten my apple and why? Dr J R Stockton <reply1239@merlyn.demon.co.uk.invalid> - 2012-09-29 20:47 +0100
          Re: Who's eaten my apple and why? Christoph Becker <cmbecker69@gmx.de> - 2012-09-27 13:00 +0200
            Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-27 09:34 -0700
              Re: Who's eaten my apple and why? Christoph Becker <cmbecker69@gmx.de> - 2012-09-27 19:14 +0200
                Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 21:40 +0200
                Re: Who's eaten my apple and why? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-28 15:39 +0200
                Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-27 16:25 -0700
      Re: Who's eaten my apple and why? Tim Streater <timstreater@greenbee.net> - 2012-09-27 08:52 +0100
  Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-26 17:50 -0700

csiph-web