Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Forms Choosing Options Select Menus

option value purpose

From MDN: option value: The content of this attribute represents the value to be submitted with the form, should this option be selected. If this attribute is omitted, the value is taken from the text content of the option element.

Is it just good practice to include the value even when it mirrors the text field (as Nick's does)? Or is there a reason to include value with option? Seems like a lot of unneccesary extra typing.

1 Answer

Let's say you have a drop down menu on an employee form and you want this drop down to represent the employee's status. It could contain the statuses "Applied", "Hired", and "Terminated". In the employee database we store the status as a number which is more efficient, so applied would equal 1, hired equal 2, and terminated equal 3. Now, if we wanted to display the status of an employee in the drop down, but when we save we only want to use our values then the drop down may look like this:

 <select>
  <option value="1">Applied</option>
  <option value="2">Hired</option>
  <option value="3">Terminated</option>
</select> 

If we stored our statuses as text then we could omit the value attribute. So in a nutshell, the value attribute allows us to assign values to our options that are different then their displayed values.

Thank you!

pat barosy
pat barosy
6,759 Points

Great example. Thank you