Drop-down List
When there are more options to choose from, a drop-down list saves space. We create it with the select element, and each option in it with an option element.
Each option has a value attribute, which is sent with the form, and its content is the text the user sees. The name and id attributes, and the label, belong to the select element, just like with an input. Unlike input, select has a closing tag, because the options go inside it.
<label for="input-pizza">Pizza</label>
<select name="pizza" id="input-pizza">
<option value="margherita">Margherita</option>
<option value="salami">Salami</option>
<option value="hawaii">Hawaii</option>
</select>This code is displayed like this:
When the user chooses Salami, the form sends pizza=salami.
In our form, the user will choose the course they want to sign up for.
Instructions
- 1
In the empty
div, create aselectelement with the attributenamewith the valuecourseand the attributeidwith the valueinput-course. - 2
Inside the
select, create threeoptionelements with the contentsHTML,CSSandJavaScriptand the valueshtml,cssandjavascript. - 3
Before the
select, create alabelwith the contentCourseand the attributeforwith the valueinput-course.