
var theRows = "<tr><th>Food</th><th>Units</th></tr>\n";
theUnits = new Array();
counter = 0;
function addRow(){
var theForm = document.frmTableGen;
theRows = theRows + "<tr><td>" +  theForm.txtFood.value + "</td><td>" + theForm.txtUnits.value + "</td></tr>\n";
theUnits[counter] = theForm.txtUnits.value;
counter++;
document.getElementById("theTable").innerHTML = "<table align=\"center\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">" + theRows + "\n</table>";
}

function calcRow(){
var unitTotal=0;
for(i=0;i<theUnits.length;i++){
unitTotal+=parseFloat(theUnits[i]);
}
theRows = theRows + "<tr><td align=\"right\"><strong>Total:</strong></td><td>" + unitTotal + "</td></tr>";
document.getElementById("theTable").innerHTML = "<p>scroll down for the HTML code</p><table align=\"center\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">" + theRows + "\n</table>";

//give the code
document.frmTableCode.style.visibility="visible";
document.frmTableCode.txtTheCode.value = "<table align=\"center\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">" + theRows + "\n</table>";
}

function selectCode(id){
id.focus();
id.select();
}
