Code does not enter if when it should

Asked

Viewed 118 times

-5

This if is correct? because if I withdraw this IF it makes the call from ajax 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>
  • @ramaral Sorry, we are editing at the same time and overwriting each other.

  • 1

    Is there an error in your console?

  • 3

    frm is not defined!

  • @bfavaretto No problem. What matters is that the question gets well formatted code.

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. o 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;"
  • o AJAX? $. ajax({ type: "POST", url: "<! -$Httpbrowserfullcgipath-->", data: "Idcservice=ENVIA_EMAIL&Issoap=1&from=" + email +"&to=" + emailInea + "&Subject=" + assunto_email + "&body=" + corpo_email }). done(Function( msg ) { Alert("Your message was successfully sent." ); });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.