Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

69
Views
How to execute code only after the submission is done?
  1. I have some code from a service called webflow where the form is controlled by them. I write the html form, but the form submission code is handled by a third party not me
  2. I need to run some code (trigger a redirect) after their submission is done.

Here is my attempt

$('#email-form').submit(function (event) {      
    window.location.href = url;
});

It works in some browser, but not in safari. Apparently, this breaks this original form submission code.

My second attempt, this works

    $('#email-form').submit(function (event) {      
    setTimeout(function(){
    window.location.href = url;
    }, 500);

});

By giving it some time, the submission code fires first, then my code runs and successfully redirects.

What is a more robust way of writing this code (not reliant on some random timer wait)?

7 months ago ยท Juan Pablo Isaza
1 answers
Answer question

0

I think the best way to work this in every browser is ๐Ÿ‘‡

setTimeout(function(){document.location.href = "your link";},250);
7 months ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs