Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML - sharing <option> values between different <select>s

Tags:

html

Is there any way to share <option> tags between different <select> tags?

I have many selects, and all of them have the same exact options. Since I don't want to populate the DOM with too many duplicates, I changed to using an input with a single datalist to share the options, however this both has issues with events (only fires a change event when unfocused, or the client presses enter), and also allows the client to write anything he wants, which really doesn't suit my case.

like image 820
user2503048 Avatar asked Aug 11 '26 16:08

user2503048


1 Answers

I don't think you can do that with straight HTML.

You can use JavaScript to populate all your SELECT tags. The OPTION tags will still appear several times in the DOM, but at least you don't be downloading them from the server.

like image 101
zmbq Avatar answered Aug 13 '26 08:08

zmbq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!