Trying to read objects from array and place them in a form. I am new to Javascript and I am struggling to understand why this doesn't work. I have tried to look online for help but so far haven't found anything.
Here is my code so far:
var arr = [
{Section: 1, Max: 20},
{Section: 2, Max: 30},
{Section: 3, Max: 50}
];
var length = arr.length;
function createForm() {
for (i = 0; i <= length; i++) {
form = document.getElementById("formed");
var x = arr.Section[i];
var y = arr.Max[i];
form.appendChild(x);
form.appendChild(y);
}
}
<head>
<meta charset="utf-8">
</head>
<body onload="createForm();">
<form id="formed">
</form>
</body>
.appendChild()needs an HTML element to append. If you want to insert data, then you need to have an element to insert it into.