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 7861931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:56:04+00:00 2026-06-02T22:56:04+00:00

I have a form that accepts numeric input from the user. Upon form submission,

  • 0

I have a form that accepts numeric input from the user. Upon form submission, a JS function is called to check the form status (if parameters are ok, etc.). One of its actions is to initiate a AJAX request to receive two values depending on its parameters (that are read from the form). So, I have a function called CheckForm() that runs on form submission and inside it, I have a block that initiates the AJAX request:

var error = 0;
function CheckForm() { // run on form submit
  var items = $('myitems');
  if (items != undefined || items != null) {
    items.each(function() {
      if (!isNaN($(this).val())) { // check for number
        $.get('myurl', {
           // parameters
        },
        function(data) {
          if (data != "0") {
            if (condition) error = 1;
          }
        });
      }
      if (error == 1) return false;
    }); // end each function
    if (error == 1) {
      alert("You have made an error.");
      error = 0;
      return false;
    }
  }
  return true;
}

I have also declared a global variable (error) to check if something wrong has happened during the check. myitems is a collection of html elements that the check runs on. So, this function is bind to the form submit click event and is run upon submission.

The question: This does not work. The alert is displayed and the browser page is instantly refreshed (form submitted) without the user clicking on the OK button first.

Is there another way to implement this?

  • 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-02T22:56:06+00:00Added an answer on June 2, 2026 at 10:56 pm

    First of all when you use a selector in jQuery the result will never be null or undefined so you can just do :

    $('myitems').each(function()....
    

    Second you have to realize you are making asynchronous calls (AJAX), which means the function CheckForm may return before even one of the get calls has finished.

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

Sidebar

Related Questions

So I have a form that accepts some input from a user that may
I have a form input field that accepts multiple tags from a user, a
I have a form that accepts user input and asks them to upload a
I have a PHP page that accepts input from a form post, but instead
I have a text field that accepts user input in the form of delimeted
I do have an html form that accepts textbox input of sha1 hashes per
I have a form field that accepts large text from users. It is basically
Conceptually, is it possible to have a form in Rails that accepts input for
Hi everyone I have a form that accepts user date entry in the form
I have a form that accepts image file, i want to be able to

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.