On Oct 25, 4:37 pm, Giovanni Battista Lenoci gian...@gmail.com
wrote:
nick ha scritto: select id=one
option value=1 selectedone/option
option value=2two/option
option value=3three/option
/select
The right syntax is :
option value=1 selected=selectedone/option
Only if the OP is serving XHTML as XHTML, which is rare on the web. If
the markup is being served as HTML (which covers the vast majority of
web pages) then what the OP posted is valid markup.
If there is no selected then it always defaults to first value. How
can I tell if the page has loaded and no options have been selected?
The selectedIndex value of the select element will be -1:
URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-85676760
This is the way the select element works, there is always a selected
element, even if you don't interact with the element.
There is no requirement for an option to be selected by default:
URL: http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT
therefore you should not expect that one will be. It is prudent to
include the selected attribute for the option that should be selected
by default, even if it's the first one, as suggested by the HTML
specification:
| 17.6.1 Pre-selected options
|
| Zero or more choices may be pre-selected for the user.
| [...]
| Since user agent behavior differs, authors should ensure that each
| menu includes a default pre-selected OPTION.
--
Rob