About HTML drop-down list and its attributes
An HTML drop-down list is created using the <select> element, which creates a drop-down list of options.
Each option within the list is represented by an <option> element, which is nested inside the <select> element.
Attributes of the <select> element:
name: specifies a name for the drop-down list that can be used to reference it in a form.
multiple: allows multiple options to be selected at once.
size: specifies the number of visible options in the drop-down list.
disabled: disables the drop-down list, making it unclickable.
required: makes it mandatory for a user to select an option before submitting the form.
Attributes of the <option> element:
value: specifies the value that will be sent to the server when the option is selected.
selected: specifies that the option should be pre-selected when the page loads.
disabled: disables the option, making it unselectable.
Example:
<select name="fruit"
multiple>
<option value="apple">
Apple</option>
<option value="banana">
Banana</option>
<option value="mango">
Mango</option>
<option value="orange"
selected>Orange</option>
</select>
In this example, a drop-down list named "fruit" is created with four options: apple, banana, mango, and orange. The "multiple" attribute is used to allow the user to select multiple options at once, and the "selected" attribute is used to pre-select the "orange" option when the page loads.
No comments:
Post a Comment