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


Groups > comp.lang.javascript > #28415

Re: Retrieve a select from a table cell

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Retrieve a select from a table cell
Date 2015-07-14 16:54 +0200
Organization PointedEars Software (PES)
Message-ID <1461265.Ovo60OvCif@PointedEars.de> (permalink)
References <mo2utl$9s5$1@dont-email.me> <mo308p$hct$1@solani.org>

Show all headers | View raw


Christoph M. Becker wrote:

> danca (Daniele Campagna) wrote:
>> Hi all, I'm trying to retrieve the value of a <select> in a table cell.
>> However, I noticed a different behaviour if i create the element via
>> HTML or if I create it via createElement() and then appendChild()
> 
> Well, remove all whitespace between the tags in the HTML version, and
> most likely you get the same behavior.

ACK.
 
>> Now I put an onclick() on cells just to see the firstChild element of
>> the TD in the cell:
> 
> Node.firstChild does not necessarily yield the the first child *element*
> of the node.  If you want to get that, use ParentNode.firstElementChild
> (you may want to write a wrapper/fallback in case the method is not
> supported).
> 
> Alternatively, you can retrieve all select elements with
> Element.getElementsByTagName("select").

You are writing interface names as if they would refer to objects.  This is 
confusing, and wrong if taken verbatim, because in recent DOM 
implementations those names can and do refer to objects, but not to objects 
that implement the interface, but objects that provide access to its 
features via the prototype chain.  Unfortunately, this mistake of 
oversimplification is perpetuated by references such as MDN.

[I am writing Element::getElementsByTagName(…) when I am referring to the 
abstract method of the interface, and element.getElementsByTagName(…) when I 
am referring to the implemented method of the element object referred to by 
“element” instead.]

The most compatible and most efficient approach here is to give the control 
a name (“name” attribute), make it part of a form (descendant of a “form” 
element), and refer to it by the corresponding form object and control name 
if necessary (always consider the “this” value first).  Giving the control 
an ID (“id” attribute) and referring it by that using 
document.getElementById(…) is second to the former in backwards 
compatibility; but maybe not in efficiency, particularly not if there are 
several controls with the same name and one only wants to access one of 
them.

The FAQ Notes have more on this.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

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


Thread

Retrieve a select from a table cell "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-14 14:24 +0200
  Re: Retrieve a select from a table cell "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-07-14 14:45 +0200
    Re: Retrieve a select from a table cell Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-14 16:54 +0200
      Re: Retrieve a select from a table cell "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-07-14 23:20 +0200
    Re: Retrieve a select from a table cell "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 09:11 +0200
  Re: Retrieve a select from a table cell Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-14 21:36 +0200
    Re: Retrieve a select from a table cell Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-14 21:41 +0200
    Re: Retrieve a select from a table cell "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 09:10 +0200
      Re: Retrieve a select from a table cell Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-15 09:46 +0200
        Re: Retrieve a select from a table cell "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-15 10:03 +0200
          Re: Retrieve a select from a table cell "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-07-15 06:33 -0700
        Re: Retrieve a select from a table cell "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 10:17 +0200
          Re: Retrieve a select from a table cell Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-15 11:47 +0200
            Re: Retrieve a select from a table cell "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 13:11 +0200
              Re: Retrieve a select from a table cell Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-18 18:04 +0200
  Re: Retrieve a select from a table cell Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-07-14 16:44 -0300
    Re: Retrieve a select from a table cell Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-07-14 17:03 -0300
      Re: Retrieve a select from a table cell Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-14 22:07 +0200
        Re: Retrieve a select from a table cell Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-07-14 17:28 -0300
          Re: Retrieve a select from a table cell Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-15 00:23 +0200
    Re: Retrieve a select from a table cell Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-14 22:02 +0200

csiph-web