In index.html
there is a datalist in a <form>
that looks like:
<input id="my_input" type="email" list="my_list" multiple>
<datalist id="my_list">
<option value="Number 1">
<option value="Number 2">
<option value="Number ...">
<option value="Number N-1">
<option value="Number N">
</datalist>
<input type="submit"> <!-- Leaving out the form code for this MWE. -->
It is desirable for the (large number of) option
items to be pulled out of the main HTML file and into some external file, without having to use Javascript to dynamically create the datalist.
Pseudo code demonstrating what is wanted:
# data.html
<datalist id="my_list">
<option value="Number 1">
<option value="Number 2">
<option value="Number ...">
<option value="Number N-1">
<option value="Number N">
</datalist>
and
# index.html
<input id="my_input" type="email" source="data.html" list="my_list" multiple>
<input type="submit">
The solution doesn't have to be broken out exactly like above, as long as:
- The (large number of)
option
values are in a separate file. - A form in
index.html
is able to get the selected datalist items to submit. - Javascript isn't needed to construct the datalist in
index.html
.
The first thing I tried was HTML imports, but it turns out they're deprecated, so I didn't pursue it very far. Then I sunk a bunch of time into trying to do this with the object tag, but it seems Javascript is necessary to get the values.
Is there a way to do this in HTML?