I'm currently working on a page that takes user input, adds it to an array, and then creates a select and option list from that array.
<!DOCTYPE>
<html>
<head>
<script>
var optionList = [];
for (var i = 0; i < optionList.length; i++){
var opt = optionList[i];
var option = document.createElement("option");
var select = document.getElementById("select");
option.setAttribute("id", opt);
option.setAttribute("class", "intersect-option");
option.value(opt);
select.appendChild(option);
}
function addOption(){
var name = document.getElementById("name").value;
name.push(optionList());
}
</script>
</head>
<body>
<input type="text" id="name" value="">
<input type="button" onclick="addOption()" value="Add Person">
<select id="select">
</select>
</body>
</html>
The problem I'm facing is that when I try to input information, I get the following error message:
Uncaught TypeError: optionList is not a function
at addOption (selectTest.html:19)
at HTMLInputElement.onclick (selectTest.html:25)
I'm unsure of what I'm doing wrong, and any assistance would be greatly appreciated.