I want to validate few inputs before submiting the form, i am doing this
$(document).ready(function(){
$('#form_arc_packages').submit(function(e){ /*should i use focus or similar, here?*/
e.preventDefault();
if(validarFormulario()==true){
$('#form_arc_packages').submit(); /*Am i starting an infinite loop, here?*/
}
});
});
where
function validarFormulario(){
var valido = true;
$('.errorCanc').slideUp();
var fecha1=$('#date1').val();
var fecha2=$('#date2').val();
var area1=$('#area1').val();
var area2=$('#area2').val();
if (fecha1.length < 1){ $('#date1').next('.errorCanc').slideDown(); valido = false; }
if (fecha2.length < 1){ $('#date2').next('.errorCanc').slideDown(); valido = false; }
if (area1.length < 1){ $('#area1').next('.errorCanc').slideDown(); valido = false; }
if (area2.length < 1){ $('#area2').next('.errorCanc').slideDown(); valido = false; }
return valido;
}
Just checking the lenght of the inputs, for now, but the problem is that the form won’t be submited (even when all inputs are set and with console.log i am making sure that validarFormulario returns true),
EDIT
And like this:
$(document).ready(function(){
$('#form_arc_packages').submit(function(e){
if(validarFormulario()==true){
$('#form_arc_packages').submit();
}else{
//Post didn't pass validation, so prevent posting
e.preventDefault(); return false;
}
});
});
Seems to work ok in Firefox but for example, in IE7, it shows the errors (with the slideDown) and then stills submit the form… -EDIT- ignore this, it happened because of the console.log() i was using. works fine.
What am i doing wrong?
Change it to this…