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

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

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