I am very VERY new to HTML/CSS/Javascript and stackoverflow. I'm trying to teach myself some user inputs. Currently, I'm stuck trying to use datalists.
Under my head tag I have successfully created an input that uses the datalist boxlist using HTML. Yay!
However, I have no idea how to make the inputs created on the button press (i.e created in the javascript addFields function) also use the boxlist datalist.
How can I get the newly created input fields to use the boxlist datalist? Is it possible to declare the datalist in javascript, and still have it used by the new fields?
function addFields() {
var input = document.createElement("input");
document.body.appendChild(input);
}
<head>
<input name="box" list="boxlist" />
<datalist id="boxlist">
<option value="Item1"></option>
<option value="Item2"></option>
<option value="Item3"></option>
<option value="Item4"></option>
</datalist>
<button type="button" onclick="addFields()">Add input</button>
</head>