Please the for loop inside the event listener is not working properly. It only loops once instead of the number of times the user wants it to and also saving the values entered by the user in the table with unique variable names.Thank you as u help
<html>
<script>
var body = document.body,
Tbl = document.createElement('table');
tbl.style.width = '100px';
tbl.style.border = '2px solid yellow';
var n = 3;
for (var i = 0; i < n; i++) {
var tr = tbl.insertRow();
var td = tr.insertCell(0);
var tf = tr.insertCell(0);
var input = document.createElementeElement('input');
input.name = "inputa" + i ;
input.id = "inputa" + i;
input.value = "";
var clone = input.cloneNode();
clone.name = "inputb" + i;
clone.id = "inputb" + i;
td.appendChild(clone);
tf.appendChild(input);
td.style.border = '2px solid yellow';
tf.style.border = '2px solid yellow';
}
var form = document.createElement("form");
form.appendChild(tbl);
body.appendChild(form);
var submit = document.createElement("input");
submit.type = "submit";
form.addEventListener('submit', function(event) {
event.preventDefault();
for (var r = 0; r < n; r++) {
var c = document.getElementById("'inputa' +n-(n-1)").value;
var d = document.getElementById("'inputb' +n-(n-1)").value;
f=+c+ +d
document.write(f);
document.write(c);
}
});
form.appendChild(submit)
tableCreate();
</script>
</html>
Tblthen use the variabletbl. These are not the same.