How to create a cell with attributes? (see attachment)

wxdqz

New Member
Hi,
It's my first time in this forum, and here is my question:
How can I create an element with id's?
i.e, I have the following table:

<TABLE ID='MyTable' BORDER=1>
<TBODY>
<TD ALIGN='CENTER' id='cell_11' MyValue = '1'>Value1</TD>
</TBODY>
</TABLE>

I insert a row below the existing one, using the following function:

function Add_Record(){
var tbody = document.getElementById('MyTable').getElementsByTagName("TBODY")[0];
number_of_rows = document.getElementById('MyTable').rows.length + 1;
MyLabel = 'value ' + number_of_rows;
var row = document.createElement("TR");
var td1 = document.createElement("TD");
td1.appendChild(document.createTextNode(MyLabel));
row.appendChild(td1);
tbody.appendChild(row);
}

With this piece of code, I just have a text in the new cell, and nothing more. But I need to store '2' in the variable "MyValue" of the new cell, and "cell_21" in the "id" of the new cell. How can I create a new cell with this two attributes?

I have attached the code, if anyone wants to take a look at it.
But if you have a better one, I'll appreciate if you share it.

Thanx in advance.
 
Back
Top