I want to call action when button is pressed

Asked 1 years ago, Updated 1 years ago, 67 views

Developing web applications in Struts 1.3.
Therefore, we are using html:button.
The following JavaScript errors appear:

TypeError: document.XxxForm.submit is not a function

The jsp is described in

<html>
…
<script language="javascript">
    function func(){
        document.XxxForm.submit();
    }
</script>
…
<html:form action="/act1">
    <html:submit property="AaaButton" value="Aaa" />
    <html:button property="BbbButton" value="Bbb" onclick="func()"/>
</html:form>
<html:form action="/act2">
</html:form>
…
</html>

appears.

We would like to call act2 (different from act1) when the Bbb button is pressed.
If anyone knows how to resolve the error, or how to achieve it,
I look forward to hearing from you.

javascript java html struts

2022-09-30 15:01

2 Answers

First of all, the error document.XxxForm.submit is not a function because the form document.XxxForm does not exist.

Since you want to call act2 action with func() function, I think you can call Submit of the form below with func() function.

<html:form action="/act2">
</html:form>

If so, please change the above part as follows:

<html:form name="XxxForm" action="/act2">
</html:form>

You should be able to call act2 in document.XxxForm.submit() by setting the form to the name XxxForm.


2022-09-30 15:01

Try document.forms[0].submit().


2022-09-30 15:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.