Si cela peux t'aider voici un script que j'ai écrit qui te permet d'utiliser un objet de type DataTable (voir code) qui facilite l'utilisation de tables à deux dimensions:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>TableDemo</title>
<style>
table,tr{
background-color: #2222ff;
border-width: 1px;
border-style: solid;
}
td{
background-color: #aaaaff;
padding: 2 4 2 4;
}
</style>
<script language="javascript" type="text/javascript">
/*
Author: Philippe Fery (HackTrack) philippefery@hotmail.com
Creation: May 6th, 2004
Crée une table à deux dimensions en prenant comme paramètres:
r : le nombre de rangs du tableau
c : le nombre de colonnes du tableau
Le tableau créé est 0-based. Pour adresser la 1ère cellule du 1er rang il faut donc utiliser les index (0,0)
Ce script peut être inclus dans vos pages si vous en mentionner la source
*/
function DataTable(r, c){
this.rowCount=r;
this.colCount=c;
this.table=new Array(this.rowCount);
this.init=initTable;
this.toHTML=htmlTable;
this.appendToDocument=append;
this.getData=getData;
this.setData=setData;
this.getRow=getRow;
this.getRowCount=getRowCount;
this.getColCount=getColCount;
this.init();
}
/*
Initialize the table
*/
function initTable(){
for(row=0 ; row<this.rowCount ; row++){
r = new Array(this.colCount);
for(col=0 ; col<this.colCount ; col++){
r[col] ="z_"+row+"_"+col;
}
this.table[row] =r;
}
}
/*
Read data in the specified cell (0-based)
*/
function getData(row, col){
return this.table[row][col];
}
/*
Insert data in the specified cell (0-based)
*/
function setData(row, col, data){
this.getRow(row)[col]=data;
}
/*
Returns a row
*/
function getRow(index){
return this.table[index];
}
/*
Returns the number of rows
*/
function getRowCount(){
return this.rowCount;
}
/*
Returns the number of columns
*/
function getColCount(){
return this.colCount;
}
/*
Generates a html table based on DataTable content
*/
function htmlTable(){
html = "<table>";
for(row=0 ; row<this.rowCount ; row++){
html +="<tr>";
r = this.getRow(row);
for(col=0 ; col<this.colCount ; col++){
html +="<td>";
html += r[col];
html +="</td>";
}
html +="</tr>";
}
html +="";
html +="";
html +="";
html +="";
html +="</table>";
return html;
}
function append(){
tableDiv = document.createElement("span");
html = this.toHTML();
tableDiv.innerHTML = html;
document.body.appendChild(tableDiv);
}
</script>
</head>
<body>
<script language="javascript" type="text/javascript">
myTable = new DataTable(5,3);
alert("Nombre de rangs: " + myTable.getRowCount());
alert("Nombre de colonnes: " +myTable.getColCount());
myTable.setData(0,0,"a");
myTable.setData(2,2,"b");
alert(myTable.getData(0,0));
myTable.appendToDocument();
</script>
</body>
</html>
;-)