Questa è la funzione disegna() che disegna la tabella:
Codice PHP:
function disegna(box,path)
{
st ="<table border=1>";
st+="<tr><td><button value=\"cre\" id=\"crescente\" onclick=\"crescente(0);\"></button></td><td><button value=\"dec\" id=\"decrescente\" onclick=\"decrescente(0);\"></button></td>"+
"<td><button value=\"cre\" id=\"crescente\" onclick=\"crescente(1);\"></button></td><td><button value=\"dec\" id=\"decrescente\" onclick=\"decrescente(1);\"></button></td>"+
"<td><button value=\"cre\" id=\"crescente\" onclick=\"crescente(2);\"></button></td><td><button value=\"dec\" id=\"decrescente\" onclick=\"decrescente(2);\"></button></td>"+
"<td><button value=\"cre\" id=\"crescente\" onclick=\"crescente(3);\"></button></td><td><button value=\"dec\" id=\"decrescente\" onclick=\"decrescente(3);\"></button></td></tr>";
st+="<tr><td colspan=2><span>Nome</span></td><td colspan=2><span>Codice</span></td><td colspan=2><span>Valore</span></td><td colspan=2><span>Validità</span></td></tr>";
for (var y in this.array)
st+="<tr id=\""+y+"\"></tr>";
st+="</table>";
document.getElementById(box).innerHTML=st;
for (var y in this.array)
this.posiziona(y);
//inserisco i pulsati di salvataggio
st="
<input type=button id='salva' value='salva' onclick='miaTabella.crea_form(\""+path+"\");'/>";
st+="<input type=button id='cancella' value='annulla' onclick=\"miaTabella.array_modifiche=new Array(); miaTabella.disegna('"+box+"','"+path+"');\" /> ";
document.getElementById(box).innerHTML+=st;
}
function posiziona(indice)
{
aux="";
if (this.array_modifiche[indice]!=undefined)
aux = this.array_modifiche[indice].split(":");
else if (this.array[indice]!=undefined)
aux = this.array[indice].split(":");
st="";
if (this.controlla_array(aux))
for (var y in aux)
{
st+="<td colspan=2 id=\""+indice+"_"+y+"\" onclick=\"miaTabella.modifica(indice,this.id,this.value); \">"+aux[y]+"</td>";
}
else
{
return false;
}
document.getElementById(indice).innerHTML = st;
}
la funzione disegna() inserisci i tag <table> e <tr> mentre posiziona(), inserisce i tag <td> con l'evento onclik, di seguito la funzione modifica():
Codice PHP:
function modifica(indice,id,valore)
{
st+="<td colspan=2 id=\""+indice+"_"+id+"\"><input type=\"text\" />"+valore+"</td>";
document.getElementById(indice).innertHTML = st;
}