Click to See Complete Forum and Search --> : Array of cell of a table


Geudens
March 19th, 2003, 10:58 AM
How can I make an array of cells of a table? And I want to change the properties with VbScript

nategrover
March 19th, 2003, 05:25 PM
It depends on what you're asking, but you should probably not do it in vbScript. Use javascript which is an implementation of the ECMA script specifications which means it is standards compliant (for the most part).

If you're trying to create an array that represents an existing set of cells within a table, there's a couple ways to do it.

The table.cells property works in internet explorer ie. It gives you a sequentially ordered array of all the cells in the table, so cells[3] is the fourth cell starting with the topmost left.

Using standards compliant DOM methods, you can get the table object and then get each array of row's cells one at a time.

So, table.childNodes[0] is the first row. table.childNodes[0].childNodes is the array of cells within the first row, and so on.


If you want to create an array on the fly, you use the document.createElements("TD") method and put each cell you create into a regular old javascript array. For inserting the cells into a row, you get a handle on the row object that you want to put them into, and for each cell in the array, you shoudl call
appendChild on the row, like so:


cellsArray[0] = document.createElement("TD");
// add stuff to the cell
cellsArray[1] = document.createElement("TD");
// add stuff to the cell
cellsArray[2] = document.createElement("TD");
// add stuff to the cell


for(var i=0;i<cellsArray.length;i++){
myRow.appendChild(cellsArray[i]);
}

Geudens
March 20th, 2003, 11:50 AM
I'm making a table and if you go over the cells with the mouse then they the color should change.

I gave every cell a name and then for every cell I made a sub. But I want to make one sub for all the cells.

How can I do this?

nategrover
March 20th, 2003, 11:55 AM
Create two style rules.

TD.normal{
background-color:white;
}

TD.hover{
background-color:black;
}


then, add these two event handlers to each Table cell:

onmouseover = 'this.className="hover";'
onmouseout = 'this.className = "normal";'