You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Sobkowski, Andrej" <An...@emergis.com> on 2001/11/13 22:58:14 UTC
Tip: Struts and Javascript's "error on page" with submit()
Hello,
I just wanted to post this message as I've wasted 2 hours trying to
understand what was wrong and I finally got it. There have been many
messages related to using Javascript to submit to different actions so I
hope someone will find the following useful.
* Situation (that generates an ERROR - at least on MSIE6.0 and NS6.2):
<script language="javascript">
function submitTo(newAction) {
document.forms[0].action.value = newAction;
document.forms[0].submit();
}
</script>
...
<input type="hidden" name="action" value="action2">
<a href="javascript:submitTo('action1');">Submit form with Action1</a>
<html:submit>Submit form with Action2 (the default)</html:submit>
This did NOT work in my case. Netscape's JS console says "submit is not a
method" or similar. IE just says "Error(s) on page".
* Problem
It may be evident for most of you, but the <html:submit> tag generates a
submit button with a default name of "submit"; this is why JS gets confused,
it mixes the submit() method of the form with the submit element (generated
by the tag) of the form.
* Solution
Use the property attribute to generate a submit button with a different
name:
<html:submit property="whatever">Submit form with Action2</html:submit>
This will work as the naming conflict has disappeared.
Andrej