W3C home > Mailing lists > Public > public-html@w3.org > December 2009

Re: Setting selectedIndex before adding option with that index

From: Geoffrey Sneddon <gsneddon@opera.com>
Date: Tue, 15 Dec 2009 16:54:16 +0100
Message-ID: <4B27B128.2060408@opera.com>
To: HTML WG <public-html@w3.org>
Geoffrey Sneddon wrote:
> Given the following HTML document:
> 
> <!doctype html>
> <select></select>
> <script>
> var s = document.getElementsByTagName('select')[0];
> s.selectedIndex = 0;
> s.options[s.options.length] = new Option();
> alert(s.selectedIndex);
> </script>
> 
> At the moment the spec says we should alert -1. At the moment Opera 
> alerts -1, and all other browsers alert 0. If you comment out the 
> creation of the object, all give -1.
> 
> <http://www.ticketmaster.com/> relies upon it giving 0, so Opera's 
> behaviour is going to have to change to match other browsers, leaving 
> HTML 5 in a state where nothing matches the spec. It'd seem silly for 
> the spec to stay in such a state.
> 
> I think the behaviour needed is that setting selectedIndex stores its 
> value in a buffer if it doesn't already exist, and then acts as if it 
> had just been set when the option is added. (Probably spec'd some 
> totally different way, but that's the basic change.)

It appears I didn't look at this close enough. As far as I can tell, the 
spec is currently correct for selectedIndex. What is wrong is that 
adding an option to a select element should set its selectedness to true 
if there are no options that are already selected.


-- 
Geoffrey Sneddon  Opera Software
<http://gsnedders.com/>
<http://www.opera.com/>
Received on Tuesday, 15 December 2009 15:55:00 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:15:55 UTC