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> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn 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+&. 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@O X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:17404 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: >> >> >> >>
>> >>
>> >> 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("> 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("> 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