I am trying to get a table to display properly using the following code. The problem is that the </tbody> and </table> tags are being applied before the for loop enters the data into the table. The table head displays fine and the data displays fine as well, just not in the table. What am I doing wrong? I tried moving the last line into the loop with in if statement but the same happens.
$.getJSON("adriver.php?type=get", function(data, status){
document.getElementById("aRightContent").innerHTML =
"<table class='table table-hover'>" +
"<thead>" +
"<tr>" +
"<th><i class='fa fa-check-square'></iclass></th>" +
"<th>ID</th>" +
"<th>Firstname</th>" +
"<th>Lastname</th>" +
"<th>UserName</th>" +
"</tr>" +
"</thead>" +
"<tbody>";
for(var i = 0; i < data.length; i++){
document.getElementById("aRightContent").innerHTML +=
"<tr>" +
"<td><input type='radio' name='selectedDriver' value='" + data[i].dID + "'></td>" +
"<td>" + data[i].dID + "</td>" +
"<td>" + data[i].dFirstName + "</td>" +
"<td>" + data[i].dLastName + "</td>" +
"<td>" + data[i].dUsername + "</td>" +
"</tr>";
}
document.getElementById("aRightContent").innerHTML += "</tbody></table>";
});
Thank you for any help.