How to specify the name for drop-down list in HTML5 ?
<select> <option value=””>option1</option> <option value=””>option2</option> </select>
<select> is a tag used to construct a dropdown list, as seen in the above code. The <option> tag, which is embedded in the select tag, is an attribute value or attributes for the selection list, with the value representing whether the option is chosen, disabled, or has certain other properties. We can use CSS to show our selection list effects and set positions like this.
Attributes: The following are some of the attributes that are included in the <select> tag
- Name: This attribute is useful for naming a control that will be sent to the server to be detected and to receive necessary value.
- Multiple:The user will pick several values from the selector list if the attribute is set to “multiple.”
- Size: The Size parameter determines the size of the scrolling box that covers the Dropdown list. It’s also useful for highlighting multiple choices from a list.
- Value: This attribute indicates whether a choice in the selection list has been chosen.
- Selected: Selected attributes allow the display of already selected list items from the list at the very beginning of page loads.
- Label: Label attribute works as another approach for labeling options value.
- Disabled: If we want a drop-down list with a disable option, we can use the disabled attribute in the HTML select list.
- onChange:When a user selects a choice from a dropdown list, an event is triggered on item selection.
- onFocus: When the user hovers the mouse over a selection list option to pick it, an event is triggered to select the object.
- Form: This attribute is used to specify one or more similar types to the select field.
- disabled: With the support of this attribute, we will keep our drop-down list hidden from the user.
- required: When filling out a form, we want to make it clear that this field allows the user to choose some value from a list before submitting the form, so in this situation, we define that the user must choose any value from the list.
Examples 1: Below is the code that illustrates a drop-down list with a name attribute.