user1032531
user1032531

Reputation: 26281

Is a value attribute required for a HTML SELECT element?

The select menu value posted to the server should be the same as the text in the OPTION element.

On the browser I am using, the following produce identical results.

Is the second script "correct" and cross browser supported?

 <select>
  <option value="AAA">AAA</option>
  <option value="BBB">BBB</option>
  <option value="CCC">CCC</option>
</select>

 <select>
  <option>AAA</option>
  <option>BBB</option>
  <option>CCC</option>
</select>

Upvotes: 5

Views: 1844

Answers (4)

m_callens
m_callens

Reputation: 6360

The short answer is no. The value attribute is not required but definitely beneficial. Typically just another way to capture the option selected from JS.

Upvotes: 2

gen_Eric
gen_Eric

Reputation: 227270

The value attribute is optional according to the HTML 4.01 and 5 specs.

https://www.w3.org/TR/html401/interact/forms.html#h-17.6

value = This attribute specifies the initial value of the control. If this attribute is not set, the initial value is set to the contents of the OPTION element.

https://www.w3.org/TR/html5/forms.html#the-option-element

The value attribute provides a value for element. The value of an option element is the value of the value content attribute, if there is one, or, if there is not, the value of the element's text [...] attribute.

Upvotes: 2

DAXaholic
DAXaholic

Reputation: 35358

According to MDN the attribute is optional as the value is inferred from the text if it is omitted

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.

Upvotes: 4

Wes Foster
Wes Foster

Reputation: 8900

Yes, you can omit the value attribute.

Taken from the w3 Standards for <option> tags:

The tag can be used without any attributes, but you usually need the value attribute, which indicates what is sent to the server.

A simple Google search goes a long way.

Upvotes: 4

Related Questions