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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:37:46+00:00 2026-06-04T01:37:46+00:00

Summary : This is a basic, stand alone web form. Just html form, with

  • 0

Summary: This is a basic, stand alone web form. Just html form, with a JQuery included for the functions.

I have a form that checks email and username for uniqueness and validity (of email). I’m using a JQuery onChange event to call each function, which is an Ajax call to a php file.

The JQuery for the username check is as follows:

$("#username").change(function() {
    var username = $("#username").val();
    var msgbox_username = $("#username_status");
    var dataString = "username="+ username;

    $("#username_status").html('<img src="images/loader.gif">Checking Availability.');
    if (username != "" && username.length >= 6){
        $.ajax({
            Type: "POST",
            url: "functions/check_username.php",
            data: dataString,
            success: function(msg_username) {
                $("#username_status").ajaxComplete(function (event, request) {
                    if (msg_username == 'Username Ok') {
                        $("#username").removeClass("red").addClass("green");
                        msgbox_username.html('<font color="Green">Available</font>');
                    } else {
                        $("#username").removeClass("green").addClass("red");
                        msgbox_username.html(msg_username); 
                    }
                });
            }
        });
        return false;
    } else {
        $("#username").removeClass("green").addClass("red");
        msgbox_username.html('<font color="Red">Username of 6 or more characters is required</font>');
    }
}); 

The check_username.php file is as follows:

<?php
$username = $_GET["username"];
include_once("../includes/connect.php");
$query = "SELECT    username 
          FROM      sss_users
          WHERE     username = '$username'";
$result = mssql_query($query);  
if(mssql_num_rows($result) > 0 && strlen($username) >= 6) {
    echo '<font color="#cc0000"><strong>' . $username . '</strong> is already in use. </font>'; 
} else {
    echo 'Username Ok'; 
}
?>

Continuing with the pattern, the email JQuery:

$("#email").change(function() {
    var email = $("#email").val();
    var msgbox_email = $("#email_status");
    var dataString = "email="+ email;

    $("#email_status").html('<img src="images/loader.gif">Checking Availability.');
    var atpos = email.indexOf("@");
    var dotpos = email.lastIndexOf(".");
    if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length){
        $("#email").removeClass("green").addClass("red");
        msgbox_email.html('<font color="Red">Valid Email Required</font>');
    } else {
        $.ajax({
            Type: "POST",
            url: "functions/check_email.php",
            data: dataString,
            success: function(msg_email) {
                $("#email_status").ajaxComplete(function (event, request) {
                    if (msg_email == 'Email Ok') {
                        $("#email").removeClass("red").addClass("green");
                        msgbox_email.html('<font color="Green">Available</font>');
                    } else {
                        $("#email").removeClass("green").addClass("red");
                        msgbox_email.html(msg_email);   
                    }
                });
            }
        });
        return false;
    }
});

And the email PHP:

<?php
$email = $_GET["email"];
include_once("../includes/connect.php");
$query = "SELECT    email 
          FROM      sss_users
          WHERE     email = '$email'";
$result = mssql_query($query);        
if(mssql_num_rows($result) > 0) {
    echo '<font color="#cc0000"><strong>' . $email . '</strong> is already in use. </font>';    
} else {
    echo 'Email Ok';    
}
?>

They each work seperately, but if I put an invalid username in the box and then put a valid email, somehow the check_username.php file is called and no matter what is in the box (valid or not) it thinks it’s a valid username.

An example is:

All functions are called on the OnChange Event

1) type in the username asdfasdf (which is available)

2) Delete the username asdfasdf from the text box (this works correctly, displaying a username must have at least 6 characters)

3) type in any valid email

Result: the valid email works correctly, but the username field (which is blank) recalls what was there before (asdfasdf) and says it is a valid username (even though the field is still blank.)

Hope this makes sense. Any suggestions?

SOLUTION

As noted below, the .ajaxComplete() was calling all functions with that tag. Therefore, when I made the following changes it worked:

$("#username_status").ajaxComplete(function (event, request) { ... code here ... });

changed to:

$("#username_status").ajaxComplete(function (event, request, settings) { ... code and new if statement ... });

And then I wrapped

if(settings.url == 'functions/check_username.php') {} 

around the validation code. This process was done for both the username and email validation.

  • 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-04T01:37:47+00:00Added an answer on June 4, 2026 at 1:37 am

    http://api.jquery.com/ajaxComplete/

    Whenever an Ajax request completes, jQuery triggers the ajaxComplete
    event. Any and all handlers that have been registered with the
    .ajaxComplete() method are executed at this time.

    Maybe both handlers are being fired.

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

Sidebar

Related Questions

I have a file that is similar to this: <many lines of stuff> SUMMARY:
Let's say I have this sub in VB.NET: ''' <summary> ''' Validates that <paramref
I have a pretty basic form that shows quiz questions along with choices: <%=
I have just begun scraping basic text off web pages, and am currently using
I have an object Title : foo Summary : foo bar Body : this
I have a dictionary like this: /// <summary> /// Gets the leave entitlement details.
I have a very basic class that is a list of sub-classes, plus some
trying to run this basic form control example on msdn. At step 1 of
I am just begining to explore the basic of using generics and would have
Summary I have written an Excel wrapper in .NET using Visual Basic and Visual

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.