I'm using the jQuery Form Plugin to bind the submit events for two forms on the same page so that they are submitted to separate PHP scripts that return markup to separate divs on the page.
One form refreshes the next. I use "live" so each form has its events re-bound when it is refreshed:
$(document).ready(function() {
/* Form 1 */
$('#frmSearch').live('submit', function() {
$(this).ajaxSubmit({
target: '#divResults',
url: 'search_div.php'
});
return false;
});
/* Form 2 */
$('#frmResults').live('submit', function() {
$(this).ajaxSubmit({
target: '#divLookup',
url: 'lookup_div.php',
});
return false;
});
});
So far so good. Each form can be submitted again and again with ajax and all the bindings survive from one submit to the next.
The problem arises when I try to bind a third form and fire its submit event in the "success" option of the second form:
/* Form 2 */
$('#frmResults').live('submit', function() {
$(this).ajaxSubmit({
target: '#divLookup',
url: 'lookup_div.php',
success: function(responseText){
$('#frmLookup').submit();
}
});
return false;
});
/* Form 3 */
$('#frmLookup').live('submit', function() {
$(this).ajaxSubmit({
target: '#divMappings',
url: 'mapped_items_div.php',
});
return false;
});
When I do this, the ajaxSubmit successfully executes but then the form's default submit is performed as well, causing the page to reload. Notice that I do include the "return false;" to suppress the form's default submit, but for some reason it submits anyway.
I've found that if I "bind" on Form 3's "submit" event in Form 2's success function with the same options as the "live" for Form 3, the form's default submit is not performed. This is redundant, though, and if I can I would like to avoid doing it.
How can I suppress Form 3's default submit behaviors?