[whatwg] introduction, plus some form input ideas

Jonas Sicking jonas at sicking.cc
Wed Oct 22 09:18:57 PDT 2008


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.

We would have to define things like does the value content attribute 
change value when a new option is selected, or does it just act as a 
default value. In firefox different controls behave differently in this 
regard, I haven't yet checked what the html5 spec does.

/ Jonas



More information about the whatwg mailing list