Esempio di funzione che mantiene i valori presenti. Secondo me è meglio farlo con jQuery.
Codice PHP:
function add() {
line++;
var tab = document.getElementById('miaTabella');
var row = tab.insertRow(line);
TD_posizione = row.insertCell(0);
TD_desc = row.insertCell(1);
TD_qta = row.insertCell(2);
TD_prezzo = row.insertCell(3);
var curInput = createInput('pos['+line+']')
curInput.value = line;
TD_posizione.appendChild(curInput);
TD_desc.appendChild(createInput('des['+line+']'));
TD_qta.appendChild(createInput('qta['+line+']'));
TD_prezzo.appendChild(createInput('prz['+line+']'));
}
function createInput(inputName) {
var input = document.createElement("input");
input.type = "text";
input.name = inputName;
return input;
}