I have two forms.
you would say
<input type="submit" name="btn1" id="btn1" value="Submit"/>
$("#btn1").click(function(){
$("#frm1").submit();
}
and
<input type="submit" name="btn2" id="btn2" value="Submit"/>
$("#btn2").click(function(){
$("#frm1").submit();
}
I usually avoid the .submit() function as i almost always have to do something more with response that .submit() would allow me to do.
Thus, a non .submit option where you SUBMIT buttons would have to be changed to normal buttons.
$('.btn2').bind('click', function(){
var form1Data = $('#frm1').serialize();
$.ajax({
url : 'someurl',
type : 'post',
datatype : 'json',
data : form1Data,
success : function(json) {
sumbitForm2();
}
});
});
function submitForm2() {
var form2Data = $('#frm2').serialize();
$.ajax({
url : 'urlToSumbitForm1',
type : 'post',
datatype : 'json',
data : form2Data,
success : function(json) {
//do something if you need to
}
});
}
<button type="submit" form="form1" value="Submit">Submit</button>
The form
attribute specifies the id
of the form that the button will submit.
HTML
<form name="frm1" action="someurl" method="post" id="frm1">
<input type="submit" name="btn1" class="buttons" value="Submit"/>
</form>
<input type="submit" name="btn2" onclick="formSubmit()" value="Submit"/>
Javascript
<script>
function formSubmit()
{
document.getElementById("frm1").submit();
}
</script>
consider the HTML:
<form id="target" action="destination.html">
<input type="text" value="Hello there" />
<input type="submit" value="Go" />
</form>
<div id="other">
....
</div>
The event handler can be bound to the form:
$('#target').submit(function() {
alert('Handler for .submit() called.');
return false;
});
Click function:
$('#other').click(function() {
$('#target').submit();
});
Here is the link have a look: How can I submit form on button click when using preventDefault()?
You can use ajax to submit the first form before the second one:
$('form[name=frm2]').submit(function() {
var form1 = $('form[name=frm1]');
$.ajax({
type: "POST",
url: form1.attr('action'),
data: form1.serialize(),
async: false;
});
});