Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

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. 1

    In the empty div, create a select element with the attribute name with the value course and the attribute id with the value input-course.

  2. 2

    Inside the select, create three option elements with the contents HTML, CSS and JavaScript and the values html, css and javascript.

  3. 3

    Before the select, create a label with the content Course and the attribute for with the value input-course.

Back

7/11

  1. 1. The Form Element
  2. 2. Text Input
  3. 3. Input Label
  4. 4. Password Input
  5. 5. More Input Types
  6. 6. Radio Buttons and Checkboxes
  7. 7. Drop-down List
  8. 8. Longer Text
  9. 9. Form Submission
  10. 10. Required Input
  11. 11. Form Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.