I have created a web page with a table that needs to add a row when the Add Row button is clicked. How do I capture the click event and do a loop to create another row in the table?
: [code] : : function addrow() { : with (document) : var table = (getElementById)? getElementById('table') : all['table']; : : table.addRow(); : }[/code] : : I haven't tested that, and I may have done some things I shouldn't, but it should give you the general idea. :
I got this code to work but how do I add a check box not just text to the table? td1.appendChild(document.createTextNode("want a check box here")) Thanks!
[code] function addRow(id){ var tbody = document.getElementById (id).getElementsByTagName("TBODY")[0]; var row = document.createElement("TR") var td1 = document.createElement("TD") td1.appendChild(document.createTextNode("column 1")) //how do I get a check box or a text field? var td2 = document.createElement("TD") td2.appendChild (document.createTextNode("column 2")) row.appendChild(td1); row.appendChild(td2); tbody.appendChild(row); }
Comments
function addrow() {
with (document)
var table = (getElementById)? getElementById('table') : all['table'];
table.addRow();
}[/code]
I haven't tested that, and I may have done some things I shouldn't, but it should give you the general idea.
:
: function addrow() {
: with (document)
: var table = (getElementById)? getElementById('table') : all['table'];
:
: table.addRow();
: }[/code]
:
: I haven't tested that, and I may have done some things I shouldn't, but it should give you the general idea.
:
I got this code to work but how do I add a check box not just text to the table?
td1.appendChild(document.createTextNode("want a check box here"))
Thanks!
[code]
function addRow(id){
var tbody = document.getElementById
(id).getElementsByTagName("TBODY")[0];
var row = document.createElement("TR")
var td1 = document.createElement("TD")
td1.appendChild(document.createTextNode("column 1")) //how do I get a check box or a text field?
var td2 = document.createElement("TD")
td2.appendChild (document.createTextNode("column 2"))
row.appendChild(td1);
row.appendChild(td2);
tbody.appendChild(row);
}
Add row
check.setAttribute('type','check');
td1.appendChild(check);
I think that's the one.