You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by rapsy <ro...@gmail.com> on 2008/07/15 17:46:20 UTC

Submit a struts form using javascript


I am using struts 1.1 and having problem submitting first form from inside
the second form.
What happens when the first form is submitted from the second form using
javascript? Does it call the 'execute" method of first form?

For example:
Here is the code:
<form name='secondForm' method='post' action='secondForm.do'>

<input type="submit" name="method" value="Go"
onclick="javascript:document.forms['firstForm'].submit();" />
</form>

In the above code, "firstForm" is a struts form and it not getting
submitted. The values are getting lost.
The weird thing is works on my local machine but when I deploy on production
server it doesn't work. Any help is greatly appreciated.

Thank you!


-- 
View this message in context: http://www.nabble.com/Submit-a-struts-form-using-javascript-tp18468491p18468491.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Submit a struts form using javascript

Posted by Lukasz Lenart <lu...@googlemail.com>.
> I am trying to submit two forms at once.

Khe? As I know, it isn't possible. If you send them to the same
action, just use one form for all the fields. If you send them to
separated actions (different action attribute), you have to made two
request at the same time, but there isn't something like
multithreading in JavaScript/WebBrowser ;-)
It can works if you will use AJAX to submit values.

> The first form is being submitted by "onclick" event which calls javascript
> form.submit()

An the request goes... and browser is waiting for response

> and the second form is submitted by submit button itself when
> it is clicked. The first form submission is failing i.e when I try to
> retrieve the values of the first form later in the application it is blank.

And probably, the second request override the first one, that's why
you got blank form.

> It is working on local machine but not on production server. Can there be
> some network latency issue?

Did you try access your local machine from other computer? Web browser
can behave differently base on localhost address, it allows for more
for localhost, than for remote address. Try to access your local
version from some other computer.

> Is there a better way to submit two forms?

AJAX


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Submit a struts form using javascript

Posted by Dave Newton <ne...@yahoo.com>.
--- On Tue, 7/15/08, rapsy <ro...@gmail.com> wrote:
> I am trying to submit two forms at once. 

Is that even possible? I guess I don't really see how that would work.

Not sure why you'd try to do that in the first place, but you'd probably have better luck (a) using a single form, or (b) copying one form's values to the other and submitting only one.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Submit a struts form using javascript

Posted by rapsy <ro...@gmail.com>.

I am trying to submit two forms at once. 

The first form is being submitted by "onclick" event which calls javascript
form.submit() and the second form is submitted by submit button itself when
it is clicked. The first form submission is failing i.e when I try to
retrieve the values of the first form later in the application it is blank. 
It is working on local machine but not on production server. Can there be
some network latency issue?
Is there a better way to submit two forms? 

Thanks for your response!

<input type="submit" name="method" value="Go"
onclick="javascript:document.forms['firstForm'].submit();" />





Lukasz Lenart wrote:
> 
>> I am using struts 1.1 and having problem submitting first form from
>> inside
>> the second form.
>> What happens when the first form is submitted from the second form using
>> javascript? Does it call the 'execute" method of first form?
> 
> I don't understand exactly what you mean, when you talk about "inside
> form", could you show some real page?
> 
>> For example:
>> Here is the code:
>> <form name='secondForm' method='post' action='secondForm.do'>
>>
>> <input type="submit" name="method" value="Go"
>> onclick="javascript:document.forms['firstForm'].submit();" />
>> </form>
>>
>> In the above code, "firstForm" is a struts form and it not getting
>> submitted. The values are getting lost.
> 
> What you mean "not getting submitted"? Do you have any JavaScript error or
> what?
> 
>> The weird thing is works on my local machine but when I deploy on
>> production
>> server it doesn't work. Any help is greatly appreciated.
> 
> Do you have locally the same server as on production? Did you try to
> access application which is running on your dev machine from some
> other computer?
> 
> 
> Regards
> -- 
> Lukasz
> http://www.lenart.org.pl/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Submit-a-struts-form-using-javascript-tp18468491p18479084.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Submit a struts form using javascript

Posted by Lukasz Lenart <lu...@googlemail.com>.
> I am using struts 1.1 and having problem submitting first form from inside
> the second form.
> What happens when the first form is submitted from the second form using
> javascript? Does it call the 'execute" method of first form?

I don't understand exactly what you mean, when you talk about "inside
form", could you show some real page?

> For example:
> Here is the code:
> <form name='secondForm' method='post' action='secondForm.do'>
>
> <input type="submit" name="method" value="Go"
> onclick="javascript:document.forms['firstForm'].submit();" />
> </form>
>
> In the above code, "firstForm" is a struts form and it not getting
> submitted. The values are getting lost.

What you mean "not getting submitted"? Do you have any JavaScript error or what?

> The weird thing is works on my local machine but when I deploy on production
> server it doesn't work. Any help is greatly appreciated.

Do you have locally the same server as on production? Did you try to
access application which is running on your dev machine from some
other computer?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org