Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!