Struts plus Javascript equals error

I run Javascript in Struts,when run the statement

document.forms[0].submit()

it raise follows error,

Error:Object don't support this attribute or method

Why? I am puzzled with it for several days! I still can't find why raise error!!!

Anybody can pick up me error and tell me how to correct this error? My code is follows:

<html:form method="post" action="lo.do">

<html:select property="abc" size="1" onchange="javascript:cc()">

<html:option value="1">1</html:option>

<html:option value="2">2</html:option>

<html:submit value="search"/>

</html:form>

<script language="JavaScript">

function cc(){

document.forms[0].submit();

}

</script>

[1001 byte] By [EdwardKinga] at [2007-10-2 13:06:47]
# 1
try not to use the html:submit tag instead use the ordinary html submit button.. tell me if it will work
jgalacambraa at 2007-7-13 10:31:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
If I use ordinary html submit instead of <html:submit>,it works wellWhy it don't work when I use <html:submit>?How to correct it?Thanks
EdwardKinga at 2007-7-13 10:31:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
don't know the write explantion about that but somehow i'm also using ordinary html button.. some of the struts tags were not likely identical to struts tags
jgalacambraa at 2007-7-13 10:31:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Try to close your <html:select> tag, do not specify <html:form> method attribute, do not add '.do' to your action, do not use 'javascript:' in an event and return a value :

<html:form action="lo">

<html:select property="abc" size="1" onchange="return cc();">

<html:option value="1">1</html:option>

<html:option value="2">2</html:option>

</html:select>

<html:submit value="search"/>

</html:form>

<script type="text/javascript">

function cc() {

document.forms[0].submit();

return false; // for IE

}

</script>

I use <html:submit> without any problem, even when i use events to post my form.

Hope it helps, regards

nicoreda at 2007-7-13 10:31:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Just as a clarification: returning false from a javascript event handler cancels the current action.

While that is correct for use on a submit button (ie if validation fails, then cancel submission by returning false) I don't think it is helpful in this case. The event in question is an onchange event on a select box.

Returning false in this case would actually cancel the change event, and put the value back to what it originally was - definitely NOT the intended functionality.

Cheers,

evnafets

evnafetsa at 2007-7-13 10:31:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...