furious70
04-30-2004, 12:10 PM
I'm cloning a whole table. The table has 3 columns, 1 with a link in it, 2 with input boxes. I'd like to be able to clone the table, then change the innerText and innerHTML and id of the link.
I tried this but it did not work, JS 'obj expected' error on the getElementById line for hilite_link. I'm assuming it's not finding hilite_link?
//******************build i_table
i_table = document.createElement('table');
//i_table.bgColor = 'gray';
tb = document.createElement("TBODY");
i_table_row = document.createElement('tr');
//number cell
var td=document.createElement('td');
var a = document.createElement('a')
//a.innerText = num_of_items;
//a.href = "javascript:lineHighlight(" + num_of_items + ")";
a.setAttribute('id','hilite_link');
td.appendChild(a);
i_table_row.appendChild(td);
//item num cell
var td=document.createElement('td');
var b1=document.createElement('input');
b1.setAttribute('type','text');
b1.setAttribute('name','item_num');
b1.setAttribute('id','item_num');
b1.setAttribute('size',20);
td.appendChild(b1);
i_table_row.appendChild(td);
//descr cell
var td=document.createElement('td');
var b1=document.createElement('input');
b1.setAttribute('type','text');
b1.setAttribute('name','descr');
b1.setAttribute('size',40);
td.appendChild(b1);
i_table_row.appendChild(td);
tb.appendChild(i_table_row);
i_table.appendChild(tb);
//********* end i_table
SNIP
code where I clone:
my_new_row = document.all.item_table.insertRow();
my_new_row.setAttribute('name','line_' + i);
my_new_row.setAttribute('id','line_' + i);
//cell to put i_table in
var top_td=document.createElement('td');
top_td.colSpan = 3;
clone = i_table.cloneNode(true);
//JS ERROR ON THIS LINE
a = getElementById('hilite_link');
a.innerText = num_of_items;
a.href = "javascript:lineHighlight(" + num_of_items + ")";
a.setAttribute('id','hilite_link_' + num_of_items);
top_td.appendChild(clone);
my_new_row.appendChild(top_td);
I tried this but it did not work, JS 'obj expected' error on the getElementById line for hilite_link. I'm assuming it's not finding hilite_link?
//******************build i_table
i_table = document.createElement('table');
//i_table.bgColor = 'gray';
tb = document.createElement("TBODY");
i_table_row = document.createElement('tr');
//number cell
var td=document.createElement('td');
var a = document.createElement('a')
//a.innerText = num_of_items;
//a.href = "javascript:lineHighlight(" + num_of_items + ")";
a.setAttribute('id','hilite_link');
td.appendChild(a);
i_table_row.appendChild(td);
//item num cell
var td=document.createElement('td');
var b1=document.createElement('input');
b1.setAttribute('type','text');
b1.setAttribute('name','item_num');
b1.setAttribute('id','item_num');
b1.setAttribute('size',20);
td.appendChild(b1);
i_table_row.appendChild(td);
//descr cell
var td=document.createElement('td');
var b1=document.createElement('input');
b1.setAttribute('type','text');
b1.setAttribute('name','descr');
b1.setAttribute('size',40);
td.appendChild(b1);
i_table_row.appendChild(td);
tb.appendChild(i_table_row);
i_table.appendChild(tb);
//********* end i_table
SNIP
code where I clone:
my_new_row = document.all.item_table.insertRow();
my_new_row.setAttribute('name','line_' + i);
my_new_row.setAttribute('id','line_' + i);
//cell to put i_table in
var top_td=document.createElement('td');
top_td.colSpan = 3;
clone = i_table.cloneNode(true);
//JS ERROR ON THIS LINE
a = getElementById('hilite_link');
a.innerText = num_of_items;
a.href = "javascript:lineHighlight(" + num_of_items + ")";
a.setAttribute('id','hilite_link_' + num_of_items);
top_td.appendChild(clone);
my_new_row.appendChild(top_td);