public int getSelectedIndex() { HTMLOptionsCollection options = getOptions(); int len = options.getLength(); for (int i = 0; i < len; i++) { HTMLOptionElement option = (HTMLOptionElement) options.item(i); if (option.getSelected()) { return i; } } return -1; }
public void setSelectedIndex(int selectedIndex) { HTMLOptionsCollection options = getOptions(); int len = options.getLength(); if (selectedIndex < 0 || selectedIndex >= len) { throw new DomDOMException(DOMException.INDEX_SIZE_ERR); } for (int i = 0; i < len; i++) { HTMLOptionElement option = (HTMLOptionElement) options.item(i); option.setSelected(i == selectedIndex); } }
public HTMLOptionsCollection getOptions() { DomHTMLCollection ret = new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this); ret.addNodeName("option"); ret.evaluate(); return ret; }
public void remove(int index) { HTMLOptionsCollection options = getOptions(); int len = options.getLength(); if (index < 0 || index >= len) { throw new DomDOMException(DOMException.INDEX_SIZE_ERR); } HTMLOptionElement option = (HTMLOptionElement) options.item(index); option.getParentNode().removeChild(option); }