HTML Select and Textarea
select, textarea, datalist, and output cover choices, longer notes, suggestions, and calculated results that a single-line input cannot express honestly.
Some questions need a list of options, a longer written answer, a suggestion list, or a calculated result. select, textarea, datalist, and output cover those jobs. They still need visible labels and submitted names from the HTML Forms lesson.
Build a labeled select with honest options
select contains option children. The submitted value is the selected option’s value, or its text if value is omitted. optgroup labels a subset of options. multiple lets more than one option be chosen; that changes both the interface and the submitted data. A first placeholder option with value="" and required can force a real choice.
<label for="experience">HTML experience</label>
<select id="experience" name="experience" required>
<option value="">Choose one</option>
<optgroup label="Still learning">
<option value="new">New to HTML</option>
<option value="some">Some markup</option>
</optgroup>
<optgroup label="Teaching others">
<option value="mentor">I review other people’s HTML</option>
</optgroup>
</select>- Associate a visible label with the select id.
- Give every intended option a stable value.
- Use optgroup only when the grouping is real.
- multiple submits more than one value for the same name.
- Do not use select for a single action; that is a button.