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

Setting selectedIndex before adding option with that index

From: Geoffrey Sneddon <gsneddon@opera.com>
Date: Thu, 12 Nov 2009 17:39:28 +0100
Message-ID: <4AFC3A40.4030501@opera.com>
To: HTML WG <public-html@w3.org>

Given the following HTML document:

<!doctype html>
var s = document.getElementsByTagName('select')[0];
s.selectedIndex = 0;
s.options[s.options.length] = new Option();

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.)

Geoffrey Sneddon  Opera Software
Received on Thursday, 12 November 2009 16:40:02 UTC

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:45:03 UTC