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


Groups > comp.lang.javascript > #28420

Re: Retrieve a select from a table cell

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Retrieve a select from a table cell
Date Tue, 14 Jul 2015 22:02:35 +0200
Organization PointedEars Software (PES)
Lines 69
Message-ID <55A56ADB.60404@PointedEars.de> (permalink)
References <mo2utl$9s5$1@dont-email.me> <mo3oq2$qo5$1@speranza.aioe.org>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 8bit
X-Trace solani.org 1436904342 15942 eJwNysEBwCAIA8CVUAnYcSCa/Uew9z6sGMH0QDgEWabCPnAK3H00hIJn19y4pltYOETz3875ACGxEZU= (14 Jul 2015 20:05:42 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Tue, 14 Jul 2015 20:05:42 +0000 (UTC)
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0
X-User-ID eJwFwYEBACAEBMCVEp7GCd/+I3TnCkGHwWH+/JnUrp3QGKHZgnI0evLQh0uHeSWqV8tmmRyfrKsCXovn+EwwFYo=
In-Reply-To <mo3oq2$qo5$1@speranza.aioe.org>
Cancel-Lock sha1:TvK3CA2ptuyY2LnCqj8Gqh2+tFI=
X-NNTP-Posting-Host eJwFwQcBACAMAzBLO3QFObDjXwIJPDSSKxALg1HvLfaKxSsq5jfhcma/pnJIa1pVJjj7dH0TrBE4
Xref csiph.com comp.lang.javascript:28420

Show key headers only | View raw


Joao Rodrigues wrote:

> DOMcreasel() may be simplified to:
>
>   function DOMcreasel(tableID) {
>     var ns = document.createElement("SELECT");
>     ns.options[ns.options.length] = new Option('Memo', 'M');
> […]
>     var lastrow = document.querySelector("#" + tableID
>                 + ">tbody>tr:last-child");
>     var i = lastrow.cells.length;
>     lastrow.insertCell(i).appendChild(ns);
>   }

Yes, but then you would have to explain why you are combining the oldest
proprietary with the newest standards-compliant features in an error-prone
way.

> You are adding onclick event handlers to every child of the TDs, and
> fc.firstchild may be null depending on what you click (use Firefox /
> Firebug to see it for yourself).

Correct.  But if that had been the reason here, the result would not have
been an alert message, but a TypeError exception as “null as no properties”.

> […]
>>     var fc=this.firstChild;
>>     if (fc) {
>>      alert(fc.type+" - "+fc.nodeName+" - "+fc.value+" - "+fc.nodeType)
>>     }
>> […]
>>
>> When I click on the cell containing the first SELECT I have:
>> undefined - #text - undefined - 3
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> […]
>
> […]
>     var elems = tbl.querySelectorAll("input, select");
>     for (var i = 0, len = elems.length; i < len; i++) {
>       elems[i].addEventListener('click', cellClick, false);
>     }

The “click” event bubbles.  Even though you are wasting much less memory
than the OP, the loop and all those event listeners are unnecessary,
especially if one assumes W3C DOM compatibility as you do.

>   }
>
>   function cellClick(e) {
>     var fc = e.target;
>     window.alert(fc.type + " - " + fc.nodeName
>                  + " - " + fc.value + " - "
>                  + fc.nodeType);

Insufficient, even by your own account: “select” elements have child
elements.
 
.
.
.
.
.
.
-- 
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 | 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