selected attribute is used to preselect an
option in a
select list, usually at
option dynamically, after page load).
You might use this attribute when an error is found in a
form, and you want
the user to reenter data into a field in the redisplayed page. It would be
irritating for the user to have to reselect selections that had previously
been made from lists; the
selected attribute takes
care of that particular conundrum.
With a simple (one-line)
drop-down list, you may only use a single
attribute, but if the
select is used as a list box
using the multiple attribute,
it is possible to have numerous
options set as
selectedattribute is used to choose the second
<form> <label for="favoritefood">Favorite food</label> <select name="favoritefood" id="favoritefood" disabled="disabled"> <option>Cheese</option> <option selected="selected">Egg</option> <option>Cabbage</option> ⋮ </select> </form>
The only possible value
for this attribute is
It causes no compatibility issues, and has excellent support across all tested browsers.