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

104
Views
Outdated value issue in JavaScript form

Here's the HTML:

<input type="text" placeholder="Answer..." id="ansbox1">
<input type="submit" onclick="submit1();" id="sp1">

Here's my JS:

var txt1 = document.getElementById("ansbox1").value;
    
function submit1() {
  if (txt1.split(" ").join("") === atob("[base64string]").split(" ").join("")) {
    alert("Yaay!");
  }
  else { 
    alert("Nope, its wrong!");
  }
}

When I put (even the decoded matching string) in the input box, it still always shows "Nope, its wrong!".

Any error?

I referred to this, yet I still get the same issue... JS - Check if the input field equals the solution

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Since txt1 is outside the function call, it has stale data. Put it inside the function call, so it can be updated everytime.

function submit1() {
  var txt1 = document.getElementById("ansbox1").value;
  if (txt1.split(" ").join("") === atob("[base64string]").split(" ").join("")) {
    alert("Yaay!");
  }
  else {alert("Nope, its wrong!");}
}
about 4 years ago · Juan Pablo Isaza Report

0

Your txt1 variable is outside the function, which could have a stale/previous value. This variable should be put inside the function so that it's always updated:

function submit1() {
  var txt1 = document.getElementById("ansbox1").value;

  if (txt1.split(" ").join("") === atob("[base64string]").split(" ").join("")) {
    alert("Yaay!");
  }
  else {
    alert("Nope, its wrong!");
  }
}
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!