|
From: DEMATTEIS, M. S [AG-Contractor/1000]
<mar...@mo...> - 2003-02-24 17:35:37
|
I get an error when HtmlSelect.setSelectedAttribute() triggers an onChange
event handler that uses "this.form" syntax to pass a form object to the
handler. I don't see the error when I access form elements in the handler
using "document.myform" syntax.
Question 1:
Is something incorrect in my HTML/JavaScript?
Question2:
When I use the command line "java Test6 hello", why don't I see " text1
value = MO" as output?
Thanks.
Mark
-------------------------------------------------------------
Heres page6.html:
-------------------------------------------------------------
<html>
<head>
<title>Page 6</title>
</head>
<script type="text/javascript" language="JavaScript">
function doChange1(theform) {
s1 = theform.select1.value;
theform.text1.value = s1.toUpperCase();
}
function doChange2(theform) {
s1 = document.myform.select2.value;
document.myform.text1.value = s1.toUpperCase();
}
</script>
<body>
<form action="" method="POST" id="myform" name="myform">
<select name="select1" onChange="doChange1(this.form);">
<option value="">Please Select a State<option value="il">il<option
value="mo">mo</select>
<select name="select2" onChange="doChange2(this.form);">
<option value="">Please Select a State<option value="il">il<option
value="mo">mo</select>
<input type="text" name="text1">
</form>
</body>
</html>
-------------------------------------------------------------
Here's the Java code:
-------------------------------------------------------------
import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.*;
import java.net.*;
public class Test6
{
public static String arg = null;
public static void main(String[] args) throws
java.net.MalformedURLException, java.io.IOException
{
if (args.length > 0)
{
arg = args[0];
}
else
{
arg = null;
}
Test6 test = new Test6();
test.testOnChange();
}
void testOnChange() throws java.net.MalformedURLException,
java.io.IOException
{
String myUrl = "http://localhost:/page6.html";
WebClient webClient = new WebClient();
HtmlPage page = (HtmlPage) webClient.getPage(new URL(myUrl));
HtmlForm form = (HtmlForm)page.getFormByName("myform");
HtmlSelect select;
if (arg == null)
{
select = (HtmlSelect) form.getSelectByName("select1");
}
else
{
select = (HtmlSelect) form.getSelectByName("select2");
}
select.setSelectedAttribute("mo", true);
HtmlTextInput text1 = (HtmlTextInput) form.getInputByName("text1");
System.out.println("text1 value =" + text1.getValueAttribute());
}
}
-------------------------------------------------------------
Here's the output with command line: java Test6 hello
-------------------------------------------------------------
text1 value =
-------------------------------------------------------------
Here's the output with command line: java Test6
-------------------------------------------------------------
Exception in thread "main" EcmaError: lineNumber=[3] column=[0]
lineSource=[null] name=[ConversionError] sourceName=[Embedded script]
message=[The undefined value has no properties.]
errorObject=[ConversionError: The undefined value has noproperties.]
com.gargoylesoftware.htmlunit.ScriptException: The undefined value has no
properties.
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScript
Engine.java:162)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(Html
Page.java:706)
at
com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelec
t.java:142)
at Test6.testOnChange(Test6.java:44)
at Test6.main(Test6.java:22)
Enclosed exception:
ConversionError: The undefined value has no properties. (Embedded script;
line 3)
at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:581)
at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:541)
at
org.mozilla.javascript.ScriptRuntime.getProp(ScriptRuntime.java:700)
at org.mozilla.javascript.gen.c2.call(Embedded script:3)
at
org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1225)
at org.mozilla.javascript.gen.c5.call(Wrapper definition for
onChange handler:1)
at
org.mozilla.javascript.optimizer.OptRuntime.callSimple(OptRuntime.java:281)
at org.mozilla.javascript.gen.c7.call(onChange handler:1)
at org.mozilla.javascript.gen.c7.exec(onChange handler)
at org.mozilla.javascript.Context.evaluateReader(Context.java:778)
at org.mozilla.javascript.Context.evaluateString(Context.java:742)
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScript
Engine.java:154)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(Html
Page.java:706)
at
com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelec
t.java:142)
at Test6.testOnChange(Test6.java:44)
at Test6.main(Test6.java:22)
|