I am declaring the global variable isValid
to true
initially. Then when I navigate across tabs, I submit the form and upon submit, the value of isValid
is changed to false
. However, the first time I navigate, it alerts a value of true
rather than false
. For some reason, the submit function is being invoked after the alert statement. What can I do so that it is invoked before the alert statement?
var isValid = true;
$('form').on('submit', function(e)) {
e.preventDefault();
// rest of the code
isValid = false;
}
$(document).on('hide.bs.tab', '.nav-pills a', function()) {
$('form').submit();
alert(isValid);
}