From: <Mik...@su...> - 2002-11-14 20:54:21
|
Following is a patch against the latest sources that implements Javascript support for the 'onchange' event on 'select' elements. *** htmlunit-old/src/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java Sun Oct 6 14:06:16 2002 --- htmlunit-new/src/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java Thu Nov 14 14:52:16 2002 *************** *** 14,19 **** --- 14,21 ---- import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.NodeList; + import com.gargoylesoftware.htmlunit.Page; + import com.gargoylesoftware.htmlunit.ScriptResult; /** * Wrapper for the html element "select" *************** *** 101,108 **** * @param optionValue The value of the option that is to change * @exception ElementNotFoundException If a particular xml element could * not be found in the dom model */ ! public void setSelectedAttribute( final String optionValue, final boolean isSelected ) throws ElementNotFoundException { try { --- 103,112 ---- * @param optionValue The value of the option that is to change * @exception ElementNotFoundException If a particular xml element could * not be found in the dom model + * @return The page that occupies this window after this change is made. It + * may be the same window or it may be a freshly loaded one. */ ! public Page setSelectedAttribute( final String optionValue, final boolean isSelected ) throws ElementNotFoundException { try { *************** *** 129,134 **** --- 133,148 ---- option.getValueAttribute().equals( optionValue ) && isSelected ); } } + + final HtmlPage page = getPage(); + final String onChange = getOnChangeAttribute(); + + if( onChange.length() != 0 && page.getWebClient().isJavaScriptEnabled () ) { + final ScriptResult scriptResult + = page.executeJavaScriptIfPossible( onChange, "onChange handler", true ); + return scriptResult.getNewPage(); + } + return page; } |