Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda