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

281
Views
the setTimout() function doesnt work inside function

So, here is function, when I put setTimeout() function in the checkForm function it doesnt work, also tried putting it outside checkForm function and it also doesnt work.

function checkForm(event) {
    event.preventDefault();
    var name = document.getElementById('username').value;
    var email = document.getElementById('user-email').value;
    var message = document.getElementById('message').value;

    var error = "";

    if (name.length == 1 || email.length == 1 || message.length == 1) {
        error = "Min length of the fields is 2 character."
    } else if (name == "" || email == "" || message == "") {
        error = "Fields are empty."
    } else if (name.length > 15 || email.length > 20 || message.length > 100) {
        error = "Max length of the fields is 15 charcaters."
    }

    if (error == "") {
        alert("You sucessfully filled up the form.");
        setTimeout(function () {
            window.location = "https://www.ebay.com/"
        }, 5000);

    } else {
        document.getElementById('errorDiv').innerHTML = error;
    }
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You need change to window.location.href = "your link"

function checkForm(event) {
    
        setTimeout(function () {
            window.location.href = "https://www.ebay.com/";
            alert('go to ebay');
        }, 2000);

}
<button onclick="checkForm()">Check Form</button>

about 4 years ago · Juan Pablo Isaza Report

0

You try this way

setTimeout(function () {
  location.href = "https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_loc_href_set";
}, 2000);
about 4 years ago · Juan Pablo Isaza Report

0

By any chance is the alert popping up and you are not acknowledging the pop-up and this is causing the browser to wait for you to acknowledge the pop up. if that is the case remove the alert("You sucessfully filled up the form.") and check if it works

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!