tabs and forms

tabs and forms

I have what I thought would be a simple thing, but I banged my head on my desk all day and now I am asking for help.

Tabs via ajax with forms in them.  I want to make sure that the form submits before switching tabs.  I can do this all the way up until I need to check that the form validates.

Basically I need to hold off on switching the form until the response from ajax comes back.  What happens is the function doesn't wait for the forms ajaxSubmit to complete.

Any examples or ideas on this?  I also only need to submit a form on two of the four tabs. I would show code, but I got upset and removed it all to start over.  Was something like:

$( "#tabs" ).bind( "tabsselect", function(event, ui) {
var currentTab = $( "#tabs" ).tabs( "option", "selected" );
if(currentTab == 0 || currentTab == 3 ){
$('.ui-tabs-panel:visible form').ajaxSubmit(function(msg){
if(msg != 1){
okToChange = false
console.log(msg);

}

console.log('form submitted');

});
}else{

okToChange = true;
console.log('skip form submit');

}

return okToChange;
});

So the function return before the ajax request is completed.