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

161
Visualizações
random math quiz human verification

i'm trying to write a simple anti bot random math quiz to prevent some bot registration into my website, i need only help with an eventlistener, to clarify:

i want that when a human write the correct answer, automatically the button for signup is showed (without submission button) (onkeyup? onkeydown?) i can't find the right solution.

jsfiddle: https://jsfiddle.net/uxrv5zch/

var minimum = 1;
var maximum = 10;
var int1 = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
var int2 = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
document.getElementById('question').innerHTML = int1 + " " + "+" + " " + int2;
var qanswer = int1 + int2;

let hideSignup = document.getElementsByClassName('Button Button--primary Button--block')[0].style.visibility = 'hidden';

function fire() {
  var uanswer = document.getElementById('answer').value;
  if (uanswer === qanswer) {
    hideSignup = document.getElementsByClassName('Button Button--primary Button--block')[0].style.visibility = '';

  } else {
    alert("WRONG! Don't snooze during math class!")
  }
}
<div class="Modal-body">
  <div class="LogInButtons"></div>
  <div class="Form Form--centered">
    <div class="Form-group"><input class="FormControl" name="username" type="text" placeholder="Username"></div>
    <div class="Form-group"><input class="FormControl" name="email" type="email" placeholder="Email"></div>
    <div class="Form-group"><input class="FormControl" name="password" type="password" placeholder="Password"></div>
    <div class="quizcontainer">
      <h3>Random Math Quiz</h3>
      <h4 id="question">1 + 1</h4><input class="FormControl" type="text" name="answer" id="answer"></div>
    <div class="Form-group"><button class="Button Button--primary Button--block" type="submit" style="visibility: hidden;"><span class="Button-label">Sign Up</span></button></div>
  </div>
</div>

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

0

You may use an onchange listener to the input element. So whenever the value of the input element changes, the fire function will be triggered.

const answer = document.getElementById('answer');

answer.addEventListener('change', fire);

function fire(e) {
  var uanswer = e.target.value;
  if (uanswer == qanswer) {
    hideSignup = document.getElementsByClassName('Button Button--primary Button--block')[0].style.visibility = '';

  } else {
    alert("WRONG! Don't snooze during math class!")
  }
}
<div class="quizcontainer">
  <h3>Random Math Quiz</h3>
  <h4 id="question"></h4>
  <input className="FormControl" type="text" name="answer" id="answer" />
</div>

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