Prova in questa maniera...
codice:
var MyFunction =
{
num : 1,
accoda : function()
{
if(document.createElement && document.getElementById && document.getElementsByTagName) {
// crea elementi
var oTr=document.createElement("TR");
var oTd0=document.createElement("TD");
var oTd1=document.createElement("TD");
var oTd2=document.createElement("TD");
var oTd3=document.createElement("TD");
var oField=document.createElement("INPUT");
var oField1=document.createElement("INPUT");
var oField2=document.createElement("INPUT");
var oField3=document.createElement("INPUT");
// setta attributi
oField.setAttribute("type","text");
oField.setAttribute("name","partenza["+MyFunction.num+"]");
oField.setAttribute("id","partenza["+MyFunction.num+"]");
oField.setAttribute("size","10");
oField1.setAttribute("type","checkbox");
oField1.setAttribute("name","chk"+MyFunction.num);
oField2.setAttribute("type","text");
oField2.setAttribute("name","ritorno["+MyFunction.num+"]");
oField2.setAttribute("id","ritorno["+MyFunction.num+"]");
oField2.setAttribute("size","10");
oField3.setAttribute("type","text");
oField3.setAttribute("name","txt_prezzo["+MyFunction.num+"]");
oField3.setAttribute("id","txt_prezzo["+MyFunction.num+"]");
// appendi al relativo padre
oTd0.appendChild(oField1);
oTd1.appendChild(oField);
oTd2.appendChild(oField2);
oTd3.appendChild(oField3);
oTr.appendChild(oTd0);
oTr.appendChild(oTd1);
oTr.appendChild(oTd2);
oTr.appendChild(oTd3);
document.getElementById('tabella').getElementsByTagName('TBODY')[0].appendChild(oTr);
// incrementa variabile globale
MyFunction.num++
}
};
Ovviamente la funzione la richiamerai in questo modo : MyFunction.accoda();