Somewtimes, we want to make an option in a select tag carry multiple values with HTML.
In this article, we’ll look at how to make an option in a select tag carry multiple values with HTML.
How to make an option in a select tag carry multiple values with HTML?
To make an option in a select tag carry multiple values with HTML, we can set the value
attribute to JSON strings.
For instance, we write
<select name="">
<option value='{ "numSequence": [0, 1, 2, 3] }'>Option one</option>
<option value='{ "foo": "bar", "one": "two" }'>Option two</option>
</select>
to set the value
attribute of the option to objects with various properties inside.
Conclusion
To make an option in a select tag carry multiple values with HTML, we can set the value
attribute to JSON strings.