Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
Trying To Match Two Fields Before Form Submit With Javascript

I am trying to match two fields with the result in my javascript before the form gets submitted but not working.

I don't want the form to get submitted if the results don't match.

Please what is the solution? Thanks.

Code Below;

function Check(){
    var done=0;
    var check=document.check.phone.value;
    var check=document.check.pcode.value;
    
    if (phone=="08023" && pcode=="12345") {
 alert ("Result Match!");
              
                done=1;
return fasle;

    }
    if (done==0) {
   
alert("Result Don't Match!");

}
}
<form action=" " method="post">
 
<input name="phone" maxlength="11"  type='tel' id="phone" placeholder="0000-000-0000" required="" />
          <br/><br/>
             
<input name="pcode" maxlength="11"  type='tel' id="pcode" placeholder="0000-000-0000" required="" />

<br/><br/>

 <button class="button" onClick="javascript:Check()"  name="Submit" type="submit" value="Login"><span>Log In </span></button> 

</form>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have several mistakes in your code, I have cleaned it up a bit for you.

        function Check() {
            var done = 0;
            var phone = document.check.phone.value;
            var pcode = document.check.pcode.value;

            if (phone=="08023" && pcode=="12345") {
                alert("Result Match!");
                done = 1;
            } else {
                alert("Result Don't Match!");
            }
        }
    <form name="check" action=" " method="post">
        <input name="phone" maxlength="11" type='tel' id="phone" placeholder="0000-000-0000" required="" />
        <br /><br />
        <input name="pcode" maxlength="11" type='tel' id="pcode" placeholder="0000-000-0000" required="" />
        <br /><br />
        <button class="button" onClick="javascript:Check()" name="Submit" type="submit" value="Login">
            <span>LogIn</span></button>
    </form>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda