The SelectFormElement class represents a select input type for an HTML form. You can add and remove various options within the select element.
The following example creates a SelectFormElement object with three options. The SelectFormElement object named list, is highlighted. The first two options added specify the option text, name, and select attributes. The third option added is defined by a SelectOption object.
SelectFormElement list = new SelectFormElement("list1");
SelectOption option1 = list.addOption("Option1", "opt1");
SelectOption option2 = list.addOption("Option2", "opt2", false);
SelectOption option3 = new SelectOption("Option3", "opt3", true);
list.addOption(option3);
System.out.println(list.getTag());
The above code example
produces the following HTML code: <select name="list1">
<option value="opt1">Option1</option>
<option value="opt2">Option2</option>
<option value="opt3" selected="selected">Option3</option>
</select>