Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Cezary Tomczyk Newsgroups: comp.lang.javascript Subject: Re: Problem w/ creating dynamic TR and its TDs Date: Sun, 02 Dec 2012 00:34:27 +0100 Organization: Aioe.org NNTP Server Lines: 63 Message-ID: References: NNTP-Posting-Host: RMrsF+s1qSnxq5Qkkqjnpw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.javascript:17401 W dniu 2012-12-02 00:17, justaguy pisze: > Hi, > > 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": elm - node name attributes - object with atttributes var createElement = function(elm, attributes){ var div = document.createElement("div"), element = document.createElement(elm); for(var p in attributes){ element[p]= attributes[p]; } div.appendChild(element); return div.firstChild; }; This is just an example and probably code could be more improved. -- Cezary Tomczyk http://www.ctomczyk.pl/