[whatwg] introduction, plus some form input ideas

Ian Hickson ian at hixie.ch
Sat Nov 29 12:45:28 PST 2008


On Wed, 22 Oct 2008, Jonas Sicking wrote:
> Ian Hickson wrote:
> > > 2. select tag:
> > >    selectedindex="[num]"
> > > 
> > > implicitly set the selected index, instead of having to parse all 
> > > the option tags and insert a "selected" string, much easier to bind 
> > > to server side data, an invalid value (such as -1 or greater than 
> > > the number of option tags) would mean none are selected. this would 
> > > obviously not apply to multiple-selects
> > 
> > You can do this from script at the moment (setting the .selectedIndex 
> > attribute). I haven't added it to the markup side yet. It doesn't seem 
> > to add much other than convenience (you can already do this with 
> > selected="", as you noted). Adding features has a high cost, even for 
> > simple features like this, and I'm not sure we can really justify the 
> > cost here.
> 
> I actually think that something like this could be of high value to 
> authors.
> 
> I've found myself many many times writing serverside code like this:
> 
> selected_value = get_default_selected();
> list_of_records = get_records_from_db();
> print("<select name='hi'>");
> foreach (record in list_of_records) {
>   print("<option ");
>   if (record.value == selected_value) {
>     print("selected ");
>   }
>   print("value='" + record.value + "'>" + record.text +
>         "</option>");
> }
> 
> 
> while this works it is quite a pain. It would be much better if you 
> could stick selected value in one place and then just dump all values. 
> Such as:
> 
> list_of_records = get_records_from_db();
> print("<select name='hi' value='" + get_default_selected() + "'>");
> foreach (record in list_of_records) {
>   print("<option value='" + record.value + "'>" + record.text +
>         "</option>");
> }
> 
> So I think it works quite well as a convenience feature.

I agree that it would be good. I have noted it as a "v2" feature. I would 
like to avoid adding this to HTML5 at the moment since we already have 
quite a lot of forms stuff and so the implementation burden is getting 
quite big -- this doesn't give quite the same bang for the buck as new 
input types.

Once there are browsers that implement the rest of the new forms features, 
though, it seems like something we should add.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list