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


Groups > comp.lang.javascript > #22715

Re: Duplicating the last row of a Table

From Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid>
Newsgroups comp.lang.javascript
Subject Re: Duplicating the last row of a Table
Date 2014-01-19 17:00 +0000
Organization Home
Message-ID <JamEt$s2SA3SFwL0@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <ZemAs3VzQa2SFwhs@invalid.uk.co.demon.merlyn.invalid> <XnsA2B97CDBE63E3eejj99@194.109.133.133>

Show all headers | View raw


In comp.lang.javascript message <XnsA2B97CDBE63E3eejj99@194.109.133.133>
, Sat, 18 Jan 2014 12:16:26, Evertjan. <exxjxw.hannivoort@inter.nl.net>
posted:

>Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> wrote on 17 jan 2014
>in comp.lang.javascript:
>
>> I wish to duplicate the last row of a Table, which contains cells like
>> <td>text</td> and <td><input type=text ...></td>, with a view to then
>> replacing the input elements with test representing their values (which
>> seems easy).
>>
>>
>> In HTML, I have something like
>>
>>         <table>         <!-- abbreviated -->
>>         <tbody ID=TB>
>>         <tr><td><input type=text ...></td><td>AA</td></tr>
>>         <tr><td><input type=text ...></td><td>BB</td></tr>
>>         </tbody>
>>         </table>
>>         <input type=button onclick="Klone()">
>>
>> and JavaScript
>>
>>         var Rose = document.getElementById("TB").rows
>>
>>         function Klone() {
>>           var node = Rose.item(Rose.length-1)
>>           var newnode = node.cloneNode(true);
>>           Rose.appendChild(newnode);
>
>You cannot do that, Rose is a collection,
>you cannot appendChild() to a collection.

I should have remembered which "educational" site I took that from ...

>Chrome console will tell you this explicitly.
>
>>           }
>>
>> which, in Firefox, produces
>> "TypeError: Rose.appendChild is not a function".
>>
>>         It may help some if I remark that this line works :-
>>                 Cel = Rose.item(Y).cells.item(X)
>>
>> What should the code be, to work in current Firefox and other common
>> browsers?
>
> function Klone() {
>          var node = Rose.item(Rose.length-1);
>          var newnode = node.cloneNode(true);
>          node.parentNode.appendChild(newnode);
> };


Typical EjH code : it works.  And with
          node.cells.item(1).innerHTML = "@@@@@"
at the end of Klone, one of the cells is overwritten.  Overwriting with
what I actually want should be easy enough ... it was.  Tested in
Firefox 26.0, Opera 12.16, Safari 5.1.7, IE8, in Win XP sp3.

Thanks.

-- 
 (c) John Stockton, nr London, UK.   E-mail, see Home Page.    Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

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


Thread

Duplicating the last row of a Table Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-17 21:44 +0000
  Re: Duplicating the last row of a Table Zlatko Duric <zladuric@gmail.com> - 2014-01-18 01:52 +0100
    Re: Duplicating the last row of a Table Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-18 12:53 +0100
      Re: Duplicating the last row of a Table RobG <rgqld@iinet.net.au> - 2014-01-19 17:00 +1000
        Re: Duplicating the last row of a Table Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-19 14:41 +0100
  Re: Duplicating the last row of a Table "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-18 12:16 +0100
    Re: Duplicating the last row of a Table Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-19 17:00 +0000
  Re: Duplicating the last row of a Table Danny <dann90038@gmail.com> - 2014-01-18 11:32 -0800

csiph-web