Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17401
| Path | csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
| 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 | <k9e45v$d6v$1@speranza.aioe.org> (permalink) |
| References | <e4c1bc98-b6a5-4142-a7a7-3fff318a7057@l12g2000vbj.googlegroups.com> |
| 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 |
Show key headers only | View raw
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:
> <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":
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/
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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