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


Groups > comp.lang.javascript > #17404

Re: Problem w/ creating dynamic TR and its TDs

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <5462881.fXVs31Ce0e@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Sun, 02 Dec 2012 03:46:44 +0100
User-Agent KNode/4.4.11
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: Problem w/ creating dynamic TR and its TDs
Newsgroups comp.lang.javascript
References <e4c1bc98-b6a5-4142-a7a7-3fff318a7057@l12g2000vbj.googlegroups.com> <k9e45v$d6v$1@speranza.aioe.org>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 104
NNTP-Posting-Date 02 Dec 2012 03:46:45 CET
NNTP-Posting-Host a4914cd3.newsspool1.arcor-online.net
X-Trace DXC=Wdj1hL<DQfD2:OR3:3gaE@ic==]BZ:afN4Fo<]lROoRAnkgeX?EC@@@JMNQ;63YamDDZm8W4\YJNLR=i2=[N6Y6JISc2lPJ3HADnbnfDmb`>@O
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:17404

Followups directed to: comp.lang.javascript

Show key headers only | View raw


Cezary Tomczyk wrote:

> W dniu 2012-12-02 00:17, justaguy pisze:
>> I've done such dynamic creation of TR and its TDs a while ago... but
>> runs into problem.
>> The thought is, if I have a current TR with ID of "row1", then the
>> following code should be able to create a new TR and its TDs and
>> append them to the "row1" Row.
>>
>> HTML:
>> <table>
>> <tr id="row1">
>>    <td><input type="text" id="myname" name="myname"><td>
>>    <td><input type="text" id="mydesc" name="mydesc"><td>
>> </tr>
>> </table>
>>
>> Javascript:
>> // find or define current row
>> var currentRow = "row1">
>>
>> // create new Row and Cells
>> var cnt = 1;
>> var newrow = document.createElement("tr");
>> var cell = document.createElement("td");
>> var cellText = document.createTextNode("<input type=text
>> name=partnumber"+cnt+ "id=partnumber"+cnt+ "class=autocomplete>");
>> cell.appendChild(cellText);
>> newrow.appendChild(cell);
>>
>> // now append the new Row and its Cells to current row
>> currentRow.appendChild(newrow);
>>
>> Question, that line of
>> var cellText = document.createTextNode("<input type=text
>> name=partnumber"+cnt+ "id=partnumber"+cnt+ "class=autocomplete>");
>> is wrong, that is, it's a text node, not an input node, and I don't
>> think there's something like createInputNode something, so, how do we
>> do it?
> 
> You can use something like this as a workaround for old IE and problems
> with "input type name":

There is no such problem.  You are confusing this with changing the value of 
the `type' property of an `input' element object after the corresponding 
element has been appended.
 
> elm - node name
> attributes - object with atttributes
> 
> var createElement = function(elm, attributes){
>      var div = document.createElement("div"),

Unnecessary; potentially harmful here (a `div' element in a `td' element).

>          element = document.createElement(elm);

OK.
 
>      for(var p in attributes){

Iterates over enumerable properties of `attributes'.  Better:

  for (var keys = Object.keys(attributes), i = 0, len = keys.length;
       i < len;
       ++i)

or pre-ES 5.1 variants thereof.  See also jsx.object.getKeys().

>        element[p]= attributes[p];

Fails to account for the mapping of attribute names that are reserved words 
to special attribute properties (like "for" → "htmlFor"), and of the `style' 
attribute.  See also jsx.dom.setAttr().

>      }
> 
>      div.appendChild(element);
>      return div.firstChild;

I beg your pardon?  What exactly are you creating the `div' element for if 
you are not returning a reference to it?  Mystical incantation?

> };
> 
> This is just an example and probably code could be more improved.

It is a solution looking for a problem while creating more problems than it 
fails to solve.   The correct way to address the problem actually posed by 
the question (as opposed to your answer) is:

  var input = document.createElement("input");
  input.name = "partnumber" + cnt;
  input.id = "partnumber" + cnt;
  input.className = "autocomplete";
  cell.appendChild(input);


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

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


Thread

Problem w/ creating dynamic TR and its TDs justaguy <lichunshen84@gmail.com> - 2012-12-01 15:17 -0800
  Re: Problem w/ creating dynamic TR and its TDs Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-12-02 00:34 +0100
    Re: Problem w/ creating dynamic TR and its TDs justaguy <lichunshen84@gmail.com> - 2012-12-01 17:06 -0800
    Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 03:46 +0100
      Re: Problem w/ creating dynamic TR and its TDs justaguy <lichunshen84@gmail.com> - 2012-12-01 19:27 -0800
        Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-03 22:53 +0100
      Re: Problem w/ creating dynamic TR and its TDs Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-12-02 08:43 +0100
        Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 16:11 +0100
          Re: Problem w/ creating dynamic TR and its TDs Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-12-02 18:48 +0100
            Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 19:35 +0100
              Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 19:39 +0100

csiph-web