Reputation: 303
Case:
I have two forms
1> Own Customized Form say form1.
2> Form rendering from third party java script call say form2.
Previously there was only one form
(no third party form) with same fields.
Thus I was submitting it using single submit button.
Lets say I was calling Action1 for my old form.
The third party form has own submit button and it post values (Not all. Only Third Party
values ) to own controller and returns response .
I don't want to ask user to submit twice on same page.
I want to submit both forms on old submit button and hide third party submit button.
I can change the response URL (where to land to get third party form submit response ).
I am thinking to hide third party submit button with css and call click/submit that when I
click old submit button using javascript.
Lets set response landing page for third party to Action1.
But if I land on old action ie Action1 I cant able to get old customized form element?
I am stuck in this scenario.
Can you have any better solution to this?
[Using struts framework and jsp for rendering form.]
Upvotes: 1
Views: 1614
Reputation: 9508
Using jQuery you may try this,
$("#submit").livequery('click', function() {
var form = $("#second_form");
var action = form.attr("action");
var serialized_form = form.serialize();
$.post(action, serialized_form, submit_first);
});
function submit_first(val) {
$("#first_form").submit();
}
2nd option
$("#form1").submit(function(){
$.post( $(this).attr("action"), $(this).serialize(),
function(){
$.post( $("#form2").attr("action"), $("#form2").seriallize(),
function(){
alert("Now what?");
});
});
});
Hope this also helpful, Submit multiple forms with jQuery and Ajax.
Upvotes: 1
Reputation: 160191
Your best bet is to use JavaScript to copy one form's parameters to the other.
The same mechanism can be used to remove the other form's submit button.
Upvotes: 0