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

111
Vistas
Trying To Use Javascript To Stop My Form From Submitting Itself When An Email Address That Has Been Used By A Previous User Is Provided

I want to add a javascript that checks and prevents my form from submitting itself whenever an email address that has been used by someone else is provided by another user. I know this is not a professional way to do this but I need this solution for a simple project.

Below is the javascript that I have tried myself but not working.

function check(form) /*function to check used email addresses*/ {
    /*the following code checkes whether the entered email address is used*/
if (form.usercheck1.value == "sttf@gmail.com" 
|| form.usercheck1.value == "dandy@gmail.com") 
{
alert("The email address you provided has been used by another user."));
    return false;
  }

  return true;
}
  
<form action='' method='POST' onsubmit="return check_usercheck1();"></form>

<input name='email' id="usercheck1" placeholder='email' required='' type='email'/>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code has various errors.

  1. check_usercheck1 function doesn't exist.
  2. Input is in outside of form.
  3. Your alert is closed 2 times with 2 ), this give a error.
  4. Yor code can be refactor.

Check the snippet below.

function check(form) {
    let emails = ['sttf@gmail.com', 'dandy@gmail.com'];
    if (emails.includes(form)) {
        alert("The email address you provided has been used by another user.");
        return false;
    }
    return true;
}

function even (e) {
  const formInp = document.getElementById("usercheck1");
  const success = check(formInp.value);
  
  if(!success) {
    e.preventDefault();
  }
}

window.onload = (event) => {

document.getElementById("form").addEventListener("submit", even);

}
<form action='' method='POST' id="form">
  <input name='email' id="usercheck1" placeholder='email' required='' type='email'/>
  <button type="submit">Submit</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