Code does not enter if when should [closed]

-5

Is this if correct? because if I remove this IF it makes the ajax call and successfully sends the fields.

<input type="submit" class="btn btn-primary" onClick='validaFrm' value="Enviar mensagem" />
<script language="JavaScript">
function validaFrm(frm) {
    if (((frm.atividades.value !=="") && (frm.numero.value !=="") && (frm.nome.value !== "") && (frm.email.value !== "") && (frm.municipio.value !== "") && (frm.mensagem.value !== "")))
    {
         EnviaEmailInstrucao("atividades","numero","nome","email","municipio","mensagem","emailInea")
    }
    else
    {
        EnviaEmailInstrucao="Erro ao enviar";
    }
}
</script>
    
asked by anonymous 09.04.2014 / 16:28

1 answer

1

It is necessary to pass the form to the function validaFrm() , this call can be made in the onsubmit of the form. the this means that you are passing the element itself (in this case the form) to the function.

<form action="suaAction" method="post" onsubmit="validaFrm(this); return false;"
    
09.04.2014 / 17:29