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

158
Views
How to run javascript code when the value of a selected item changes

function hidenv() {

  var txt = document.querySelector(".wapf-grand-total")[0].innerText;
  if (txt === "$260") {document.querySelector("button").style.display = "none";
  }
        
}
hidenv();
<input class="wapf-grand-total">
<button>button</button>

I want to hide/show the button when a element have a diferent value of $260 but with my code it only happen when i refresh the page. I need that this function run when the value change on real time but i don't know how do it.

function hide() {

  var txt = document.querySelectorAll(".wapf-grand-total")[0].innerText;
  if (txt !== "$260") {document.querySelector("button").style.display = "none";
  }
        
}
hide();

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

0

you can track changes in input fields with oninput event listener . now it will trigger your check function each time when input field is changed

function hidenv() {
  var inputEl = document.querySelector(".wapf-grand-total"),
      btn = document.querySelector("button"),
      isVal260 = inputEl.value == "$260"
      btn.hidden = isVal260
}

document.querySelector(".wapf-grand-total").addEventListener("input",hidenv)

// hidden method update suggested by @connexo
<input type="text" class="wapf-grand-total">
<button>button</button>

about 4 years ago · Juan Pablo Isaza Report

0

You should use event listener .

    document.querySelector('.wapf-grand-total').addEventListener('keyup', hide)

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!