I have a form that I am validating with jQuery, once validation is passed I want to submit the form:
$(document).ready(function(){
$('[name="form"]').submit(function(e){
e.preventDefault();
var one = $('[name="one"]');
var two = $('[name="two"]');
var three = $('[name="three"]');
var errors = [];
if(!one.val()){
errors.push(one);
}
if(!two.val()){
errors.push(two);
}
if(!three.val()){
errors.push(three);
}
if(errors.length > 0){
$.each(errors, function(i, v){
$(v).css('border', '1px solid red');
});
} else {
console.log('true');
$('#bmi-form').submit();
}
});
});
My idea was that the return true at the end would submit the form but it does nothing..
In the console I see the console.log('true');
So how can I submit the form on validation success... I dont want to use any plugins as it is a very small app and there is no need to bloat it.
Regards