Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 212
user1032531 Avatar asked Aug 09 '16 15:08

user1032531


People also ask

Does HTML select have a value?

The select tag in HTML is used to create a dropdown list of options that can be selected. The option tag contains the value that would be used when selected. The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute.

Does a select element have a value?

Each menu option is defined by an <option> element nested inside the <select> . Each <option> element should have a value attribute containing the data value to submit to the server when that option is selected. If no value attribute is included, the value defaults to the text contained inside the element.

Can select tag have value attribute?

You use selected attribute on an option element to specify default option. select elements do not have a value attribute.

Which attribute is used with select element in HTML?

The form attribute is used to explicitly associate the select element with its form owner. The name attribute represents the element's name.


1 Answers

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.

like image 57
DAXaholic Avatar answered Nov 15 '22 05:11

DAXaholic