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

  • Home
  • SEARCH
  • 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 8950651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:29:29+00:00 2026-06-15T13:29:29+00:00

Alright so i have form validation function.the function runs through form validation functions that

  • 0

Alright so i have form validation function.the function runs through form validation functions that returns false if the field isn’t valid.

The problem is when it get to the function that uses ajax to check if the field is valid.

for some reason its seems that it doesn’t “wait” for ajax to return and returns false automatically.

is there a way around this?

Here is the code:

function form_validation(){

    if (!NewValidationForm('pcode', 'Please fill in all the fields'))
        return false;
    if (!NewValidationForm('fname', 'Please fill in all the fields'))
        return false;

    if(!validate_coupon()){
        alert("bad!!");
        return false;
    }

    return true;
}

function validate_coupon(){
    var url = $j("#site_url").val() + 'ajax_functions.php';
    var coupon = $j("#pcode").val();
    var result_status = false; // seem its jumps from here to:

    $j.ajax({
    type: "POST",
    url: url,
    data: { ajax: 'ajax', coupon: coupon}
    }).success(function(insertID){
        var obj = $j.parseJSON(insertID);
        if(obj.status == 1){
            result_status = true;
        }
    });
    // straight over here
    if(result_status == true){
        return true;
    }
}
  • 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-15T13:29:29+00:00Added an answer on June 15, 2026 at 1:29 pm

    Usually in this situation I do something like this in $(document).ready():

    $('form').submit(function (evt) {
        if (!$(this).attr('data-submitted')) {
            evt.preventDefault();
            $(this).attr('data-submitted', 'true');
            // call your form validation code here that fires the ajax request
            return false;
        }
        return true;
    });
    

    Then, in your $.ajax callback, when your validation completes, call $('form').submit(). This effectively uses an attribute on the form as a flag for whether the state of the validation request. When the user first submits the form, the flag gets set and the validation process begins. When the validation completes, the form’s submit event is triggered, and since the flag is set, this time the form gets submitted like normal.

    If this approach works for you, you’ll probably want to add a little polish. For example, you’ll probably want to disable the submit button before calling $.ajax and enable it again if the validation fails. You’ll also probably want to remove the data-submitted attribute from the form if the validation fails, since the user might submit the form a second time and you presumably want to perform another validation in that case.

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

Sidebar

Related Questions

Alright say that I have on a page, say form.php. On this form say
Alright have been working to switch to jQuery 1.7's new and improved .on() function
Alright so I have a task, that I have to let the client try
Alright, so what I have is a standard select option in an HTML form,
Alright here is what I am attempting to do. I have a form written
Alright, here is my problem i'm trying to solve. I have an index page
I have a form in django and I wanna show errors before each field.
I have a user control that will handle images on a form. But depending
Alright, so I have some jQuery code that will send an AJAX request to
I have a rails 3 remote form tag that I am trying to submit

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.