HTMLDocument::addSelectElement(3) Adds a selection box


ElementTree addSelectElement( ElementTree block, String name, Int ssize, [Pair<String, [SelectOption]> ] optgroups )


parent The parent element

name The name of the input. Remember that names starting with "kaya_" may be used by the Kaya standard library and should not be used directly by applications.

ssize The size of the select element. If this is zero, the select element will only allow one option to be selected at any one time. If this is one or more, the select element will allow multiple options to be selected, and suggest to the browser that this many options be displayed simultaneously.

optgroups The options to select from


Adds a selection box to a form. The optgroups parameter is a list of pairs. The first element of the pair is the 'heading' for the option group, and the second element is a list of options in that group. For most simple selectors, a single option group with no heading (the empty string) is sufficient.

 options = [
     SelectOption("Express delivery","1",true),
     SelectOption("Standard delivery","2",false),
     SelectOption("Slow delivery","3",false)
 sel = addSelectElement(fieldset,"choice",0,[("",options)]);
 /* // produces 
   <option value='1' selected='selected'>Express delivery</option>
   <option value='2'>Standard delivery</option>
   <option value='3'>Slow delivery</option>

Using multiple groups of options is useful for larger select elements, where it can make the form clearer.

 singles = ["A1","A2","B5"];
 twins = ["A4","C2"];
 doubles = ["A7","C1","C3"];
 sopts = [];
 topts = [];
 dopts = [];
 for s in singles {
 for t in twins {
 for d in doubles {
 options = [
     ("Single rooms",sopts),
     ("Twin rooms",topts),
     ("Double rooms",dopts)
 sel = addSelectElement(roombooker,"room",0,options);

Select elements allowing multiple options to be selected have very bad usability in most browsers - it is often better to use HTMLDocument.addOptionList(3kaya) to generate a set of checkboxes instead. Whichever method you use for multiple selection, remember that you need to use WebCommon.incomingData(3kaya) to correctly retrieve the selections from the user's form submission.


Kaya standard library by Edwin Brady, Chris Morris and others ([email protected]). For further information see


The Kaya standard library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (version 2.1 or any later version) as published by the Free Software Foundation.