Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:42:50+00:00 2026-06-17T05:42:50+00:00

I am trying to use javascript on a submit button. Upon hitting the submit

  • 0

I am trying to use javascript on a submit button. Upon hitting the submit button, I run a routine that does a remote callback with callback handler h. Basing on the result of h, I’ll decide whether or not to proceed with the submit or to preventDefault and stay on the page.

I tried several approaches. First one is to run the submit using jquery after the callback:

$('#submit').on('click', function(e) {
  e.preventDefault();
  run_func_with_callback(h);
}

h() {
  if (success) {
    $('#submit').submit();
  }
}

Another one is trying for an infinite loop until a flag is changed by the call back:

callback_flag = 0;

$('#submit').on('click', function(e) {
  run_func_with_callback(h);
  while(callback_flag == 0) {
    setTimeout(function() {}, 1000); // I want some form of sleep function here
  }

  if (callback_flag == -1) {
    e.preventDefault();
  }
}

h() {
  if (success) {
    callback_flag = 1;
  } else {
    callback_flag = -1;
  }
}

However, neither of these solutions work. First one I guess jQuery just doesn’t really work that way. Second one the method I did was not a sleep function and does not behave in the way I need.

Any insights are welcomed. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:42:52+00:00Added an answer on June 17, 2026 at 5:42 am

    Sticking with your first approach, would something like this work:

    $('#submit').on('click', function(e) {
        if(!success) {
            e.preventDefault();
            run_func_with_callback(h);
        }
        else {
            success = false;
        }
    }
    
    h() {
        if (success) {
            $('#submit').click();
        }
    }
    

    The important thing is to trigger the click event in the callback and then use the value of success to conditionally execute the submission.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the JavaScript Module Pattern and I run into a
I'm trying to use the submit-function in javascript to submit a form. The reason
I'm trying to use Javascript's built-in replace() method, but for some reason it won't
I'm trying to use Javascript to access data from http://www.bart.gov/dev/eta/bart_eta.xml , however, I found
I am trying to use JavaScript to start a marquee when a user puts
I am trying to use JavaScript to set an elements width relative to their
I'm working on a project and trying to use JavaScript for validating all inputs
I am trying to use Pixastic JavaScript library for image manipulation in Windows 8
im trying to use html and javascript to create a rotating logo on my
I am trying to use the flXHR javascript library for making cross-domain calls. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.