I need to turn the default back on when my condition is true. Because I use the condition in an onclick of the submit button I can't put preventDefault inside it because it would prevent it after I clicked it and that would have no use.
So when the condition is true I need it to resume the form action. Also in the onclick I need it to react the first time and only once now +1 every time I click on it.
So in this case it has to alert Success at the first click and continue to the form page afterwards.
HTML:
<form id="formName">
<input type="submit" id="submitBtn" value="Submit" />
</form>
JS:
var a = 1;
$("#formName").submit(function(e){
e.preventDefault();
$(document).on("click", "#submitBtn", function () {
if(a != 1){
alert("Fail!");
}
else{
alert("Success");
return true;
}
});
});