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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:37:31+00:00 2026-05-31T23:37:31+00:00

I have a registration form. When I hit the Submit button it should check

  • 0

I have a registration form. When I hit the Submit button it should check if the Username is not taken and that the passwords match. So I wrote a few functions: one that checks the passwords, one that checks if the username is available and the main function, that calls for the 2 checking functions. The password checking function works nice, but my problem is with the username checking function. This is the function:

function checkIsUsernameExist(){
    if($("#txtNewUsername").val() == "") {
        $("#divIsUsernameExist").html("");
        return false;
    } else {
    $.getJSON("inc/API.php", 
        {
            command : 'isUsernameExist',
            username : $("#txtNewUsername").val(),
        },
        function(result)
        {
            if (result != true){
                $("#divIsUsernameExist").html("This username is available!");
                return true;
            } else {
                $("#divIsUsernameExist").html("This username is not available!");
                return false;
            }
        });
    }
}

When the username is empty, it does return False. But when some value is entered it returns Undefined.
Somebody told I should use Synchronous JAX (but didn’t tell me how), so I tried to write this code:

function checkIsUsernameExistAsync(){
    if($("#txtNewUsername").val() == "") {
        $("#divIsUsernameExist").html("");
        return false;
    } else {
        $.ajax({
            type: 'POST',
            url: 'inc/API.php',
            data: ({
            command : 'isUsernameExist',
            username : $("#txtNewUsername").val(),
            cache: false,
            async: false
            }),
    success: function(result){
        if (result != true){
                $("#divIsUsernameExist").html("This username is available!");
                return true;
            } else {
                $("#divIsUsernameExist").html("This username is not available!");
                return false;
            }
        }
    });
    }
}

But I get the same result – False when it’s empty, Undefined when some value is entered. I tried to change $.ajaxto $.getJSON in the second function, but still had the same result.

This is the code from API.php:

case "isUsernameExist":
        echo (isUsernameExist($_REQUEST["username"]));
        break;

it calls for a function in included page BusinessLogic.php, here’s this function:

function isUsernameExist($username)
{
    $arr = select("select * from users where username='$username'");
    if(count($arr) == 1)
    return json_encode(true);
    else
    return json_encode(false);
}

How can I make it work??

Thank you!

  • 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-31T23:37:32+00:00Added an answer on May 31, 2026 at 11:37 pm

    To summarise the comment chain:

    • Avoid synchronous AJAX requests: Remove async: false
    • Add `dataType: ‘json’,
    • return inside a success handler of jQuery.ajax does not set the return value of the outer function. To correctly pass the results, define a callback handler. Replace:
    • Before: http://jsfiddle.net/wGfzc/
    • After: http://jsfiddle.net/wGfzc/2/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple registration form. Once all information entered, user click submit button and
I have a registration form for a website that needs to check if an
I have a product registration form that allows the user to add additional product
I have a basic form that I'm using for member registration. I'm using the
I have registration form, which is saving user info in 'tblusers' -> 'Username', but
I have a registration form that when the user enters in valid registration data
I have one registration form, I don't want people to register login username with
I have a registration form which I need to validate before submit. The form
I have a registration form and am using $.ajax to submit it. This is
I'm working on a simple mobile site that have a registration form for Interest,

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.