var task_count = 1; function add_task() { var table, tbody, tr, th, td, field; var node = document.getElementById("tasks"); task_count += 1; // initialize table = document.createElement("TABLE"); tbody = document.createElement("TBODY"); tr = document.createElement("TR"); th = document.createElement("TH"); td = document.createElement("TD"); // make task name filed field = document.createElement("INPUT"); field.setAttribute("type", "text"); field.setAttribute("name", "task_"+ task_count); field.setAttribute("size", 25); th.appendChild( document.createTextNode("Task Type") ); td.appendChild( field ); tr.appendChild( th ); tr.appendChild( td ); tbody.appendChild( tr ); // make task description field tr = document.createElement("TR"); th = document.createElement("TH"); td = document.createElement("TD"); field = document.createElement("TEXTAREA"); field.setAttribute("name", "task_description_"+ task_count); field.setAttribute("cols", 50); field.setAttribute("rows", 10); th.appendChild( document.createTextNode("Task Description") ); td.appendChild( field ); tr.appendChild( th ); tr.appendChild( td ); tbody.appendChild( tr ); table.appendChild( tbody ); node.appendChild( table ); }