code: private String generateSelect(Iterable<String> choices,
        String selectedChoice, String submitUrl) {
      StringBuilder html = new StringBuilder();
      String id = "select" + lastId++;
      html.append("<select id=\"" + id + "\" name=\"" + id + "\" " +
          "onchange=\"window.location = '" + submitUrl +
          "'.replace('<CHOICE>', document.getElementById('" + id +
          "').value);\">\n");
      for (String choice: choices) {
        html.append(String.format("<option value=\"%s\"%s>%s</option>\n",
            choice, (choice.equals(selectedChoice) ? " selected" : ""), choice));
      }
      html.append("</select>\n");
      return html.toString();
    }
docs: Generate a HTML select control with a given list of choices and a given
  option selected. When the selection is changed, take the user to the
  <code>submitUrl</code>. The <code>submitUrl</code> can be made to include
  the option selected -- the first occurrence of the substring
  <code>&lt;CHOICE&gt;</code> will be replaced by the option chosen.