Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the point of the <option> "label" attribute inside <select>?

Tags:

Besides the fact that only IE7+ supports it, why would you use something such as this example? Namely:

<select>   <option label="Volvo">Volvo (Latin for "I roll")</option>   <option label="Saab">Saab (Swedish Aeroplane AB)</option> </select> 

After all, 'Latin for "I roll"' and 'Swedish Aeroplane AB' are lost (i.e., only remain in the source code).

like image 334
ezequiel-garzon Avatar asked Oct 11 '10 12:10

ezequiel-garzon


People also ask

What is the use of label for attribute?

The HTML <label> for Attribute is used to specify the type of form element a label is bound to. Attribute Values: It contains the value i.e element_id which specify the id of the element that the label is bound to.

What is option label?

Definition and Usage The label attribute specifies a shorter version of an option. The shorter version will be displayed in the drop-down list.

What is the purpose of the option tag?

Definition and Usage. The <option> tag defines an option in a select list. <option> elements go inside a <select>, <optgroup>, or <datalist> element. Note: The <option> tag can be used without any attributes, but you usually need the value attribute, which indicates what is sent to the server on form submission.

What is the function of the value attribute of the option tag of the select tag?

The value attribute specifies the value to be sent to a server when a form is submitted. The content between the opening <option> and closing </option> tags is what the browsers will display in a drop-down list.


2 Answers

In that example, the long text will be sent to the server when the form is submitted.

Given the existence of the value attribute, it is redundant.

like image 92
Quentin Avatar answered Oct 13 '22 08:10

Quentin


As per the definition of the option tag by the w3c :

"This attribute allows authors to specify a shorter label for an option than the content of the OPTION element. When specified, user agents should use the value of this attribute rather than the content of the OPTION element as the option label."

David's answer is pretty good, I just wanted to add a link to the official definition. :D

like image 36
Eric-Karl Avatar answered Oct 13 '22 09:10

Eric-Karl