1
I’m trying to validate a form to verify that everything is at least filled out. The problem is that I am not submitting the form as I cannot reload the page. I’m just capturing the event by Javascript and performing the function.
Follow the code below:
$('#nitrogenio').click(function (e) {
if($("#commentForm").validate(){
var combo=$('#haoum3').val();
var area=$('#area4').val();
var resultado;
if ( combo=="ha" ) {
resultado = 10*Number(area);
$("#divPrincipal4").html('<p class="alert-success">Irá precisar de '+ (Number(resultado)-Number(10)) +'-'+ resultado + ' Kg de Nitrogênio </p>');
}
else
{
resultado = 10*(area/Number(10000));
$("#divPrincipal4").html('<p class="alert-success">Irá precisar de '+ (Number(resultado)-Number(10)) +'-'+ resultado + ' Kg de Nitrogênio </p>');
}
}
});
To validate and prevent you from doing the function if it is empty I put a
if($("#commentForm").validate()
The idea even worked, but the problem is that when everything is correct with the form, it sends the page and reloads. Does anyone have any idea what it is?
What HTML element is the
#nitrogenio
?<button>
?<input>
?– Sergio
What do you mean, "reload" ?
– PauloHDSousa