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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:03:59+00:00 2026-05-18T07:03:59+00:00

The following is a little jQuery code that I wrote to check if a

  • 0

The following is a little jQuery code that I wrote to check if a a username and email exists in database. If they do I return false to prevent submitting the form.

The way I planned it is something like this.
On submit after other stuff is valid. I use an ajax request to check if the username exists. If It does I then check the email in the same way.

And here is the problem. I cannot set the everythingIsOK inside the ajax callback. So if everything is ok I cannot return true.

Any ideas?

$(loginForm).submit(function(){
    var = everythingIsOK = false;
    if((loginForm).valid()){
        $.get("/ajax/usernameAvailable", {username: $("#username").val()}, function(data){
            if(data.available){
                $.get("/ajax/emailAvailable", {email: $("#email").val()}, function(data){
                    if(data.available){
                        everythingIsOK = true;
                    return true;
                    }else{
                        $("#notAvailable").html("Email already exists.").show().fadeOut(8000);
                        return false;
                    }
                }, "json");
            }else{
                $("#notAvailable").html("This is username already exist.").show().fadeOut(8000);
            }
        }, "json");
    }

    return everythingIsOK;
});
  • 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-05-18T07:04:00+00:00Added an answer on May 18, 2026 at 7:04 am

    You can call the native form.submit() function (which won’t trigger this handler again) if it is ok, and return false from the jQuery handler always, like this:

    loginForm.submit(function(){
      var form = this;
      if(!loginForm.valid()) return false;
    
      $.get("/ajax/usernameAvailable", {username: $("#username").val()}, function(data){
        if(data.available){
          $.get("/ajax/emailAvailable", {email: $("#email").val()}, function(data){
            if(data.available) {
              form.submit();
            }else{
              $("#notAvailable").html("Email already exists.").show().fadeOut(8000);
            }
          }, "json");
        }else{
          $("#notAvailable").html("This is username already exist.").show().fadeOut(8000);
        }
      }, "json");
      return false;
    });
    

    When the check finishes (comes back from the server), you’ll either get an error, or the form will submit and move on. Also I changed $(loginForm above to not be wrapped again, judging by if((loginForm).valid()){ (if that isn’t erroring), it’s already a jQuery object.

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

Sidebar

Related Questions

so the following converts big endians to little ones uint32_t ntoh32(uint32_t v) { return
eHello everyone,the following is my code to display a jquery dialog window with a
Following problem: I would like to build a little clipboard with jQuery. I have
I am using the following JQuery\JavaScript code to communicate with a WCF 4 REST
I am running the following code: The first two little functions work because I
I have the following code: <html> <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js></script> <script> $(document).ready(function() { // hides
I'm a little baffled by why this is happening... I have the following code
I wrote code in which .getJSON api from jquery is used to fetch images
I have the following jQuery Code: $(#menu span).click(function() { var url = this.getAttribute(data-url); var
i've a jquery (UI) App here where the whole JQuery Code gets a little

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.