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

152
Views
How to call a javascript function only once after using an input field?

I would like to call a function for a number input, that checks if the given number is valid. My solution was to call the function using oninput in the html-tag:

<input id='tone_length_input_field' type="number" inputmode='decimal' pattern="\d*" min="0.1" max="5" step="0.1" oninput="toneLengthFieldInput(0.1, 5)">

This is the javascript-function I am calling:

function toneLengthFieldInput(min, max) {
    var input = document.getElementById('tone_length_input_field').value;
    if ((input >= min) && (input <= max)) {
        document.getElementById('tone_length_slider').value = input;
        localStorage.setItem('toneLengthEx2', input);
    } else {
        alert('please enter a value between 0.1 and 5');
    }
}

However, if I want to delete the value of the input field and type in a new one, the function is called when I delete the current value and since no value is invalid I get the error message before I can type in a new one.

Is there a way to only call the function after I am finished typing in the input field? Thanks a lot for your help :)

about 4 years ago · Juan Pablo Isaza
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!