the W3C HTML 4.01 Specification: Forms in HTML documents
17.6.1 Pre-selected options
Having not known this little bit of HTML correctness before stumbling upon it while referencing something else this evening, I would like to share it so that you may benefit from the knowledge (or I may recall on a later date). Please note that this text is taken from the W3C HTML 4.01 Specification. (Does it get any more nitpicky than this!?)
Zero or more choices may be pre-selected for the user. User agents should
determine which choices are pre-selected as follows:
- If no OPTION element has the selected attribute set, user agent behavior for choosing which option is initially selected is undefined. Note. Since existing implementations handle this case differently, the
current specification differs from RFC 1866 ([RFC1866] section 8.1.3), which states:The initial state has the first option selected, unless a SELECTED attribute is present on any of the <OPTION> elements.Since user agent behavior differs, authors should ensure that each menu includes a default pre-selected OPTION.- If one OPTION element has the selected attribute set, it should be pre-selected.
- If the SELECT element has the multiple attribute set and more than one OPTION element has the selected attribute set, they should all be pre-selected.
- It is considered an error if more than one OPTION element has the selected attribute set and the SELECT element does not have the multiple attribute set. User agents may vary in how they handle this
error, but should not pre-select more than one choice.<!ELEMENT OPTGROUP – – (OPTION)+ — option group –> <!ATTLIST OPTGROUP %attrs; — %coreattrs, %i18n, %events — disabled (disabled) #IMPLIED — unavailable in this context — label %Text; #REQUIRED — for use in hierarchical menus — >
Leave a Reply