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

118
Visualizações
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 Respostas
Responde à pergunta

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 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