Hello,
I'm a neophyte to Javascript, but I need it to dynamically add lines to a form.
I was able to cobble together this inelegant looking code below.
It adds the row when called, but there are more attributes needed for this to be correct for the application.
1) need to center the input in the TD
2)the input tags need type, size, maxsize, and value attributes added .
I have not been able to figure out the correct way to do this.
Also, is there a way for the value attribute to work with a PHP echo, or is there a Javascript method to display associative array values?
function addPart(id)
{
var tbody = document.getElementById
(id).getElementsByTagName("TBODY")[0];
var row = document.createElement("tr")
var td1 = document.createElement("td")
var td2 = document.createElement("td")
var td3 = document.createElement("td")
var td4 = document.createElement("td")
var td5 = document.createElement("td")
var td6 = document.createElement("td")
td1.appendChild(document.createElement("input"))
td2.appendChild(document.createElement("input"))
td3.appendChild(document.createElement("input"))
td4.appendChild(document.createElement("input"))
td5.appendChild(document.createElement("input"))
td6.appendChild(document.createElement("input"))
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
row.appendChild(td5);
row.appendChild(td6);
tbody.appendChild(row);
}
BTW is there an good online tutorial and/or reference for javascript or book(s) that you could recommend?