Ok here is what I am trying to. I have a form where a user will enter in the number of input fields they need (lets call them offices) and when they click the submit button a jQuery function appends the rows to a plain html table. This works fine, except I do not want the rows to be only vertical or horizontal. I want it to put three input fields on one row before going to the next. Here is the code I have:
//This function is for adding rows to the offices table
function addOfficeRows() {
var i = 0;
var counter = document.getElementById("oNum").value;
var tracking = document.getElementById("officeTracking").value;
var tracking = parseInt(tracking);
// second counter which helps determine if a new row should start or not //
var second = 1;
for(i=1;i<=counter;i++) {
if (second == 1) {
$("#p").append("<tr>");
$("#p").append("<td>" + tracking + ")" + " <input type='text' size='50' name='Office" + tracking +"' /></td>");
second = second + 1;
} else if (second == 2) {
$("#p").append("<td>" + tracking + ")" + " <input type='text' size='50' name='Office" + tracking +"' /></td>");
second = second + 1;
} else if (second == 3) {
$("#p").append("<td>" + tracking + ")" + " <input type='text' size='50' name='Office" + tracking +"' /></td>");
$("#p").append("</tr>")
second = 1;
}
tracking += 1;
}
document.getElementById("officeTracking").value = tracking;
document.getElementById("officeAddRows").value = "Add More Fields";
}
What happens is the <tr></tr> are getting appended to a "tbody" tag and rest is put outside of that tag, meaning the table is formed vertically. Any idea? Am I using append incorrectly? I am by no means an expert in jQuery so I am open to suggestions.
Thanks!