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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:43:44+00:00 2026-05-20T09:43:44+00:00

I have the following script inside a HTML page: <script> function Test(){ alert(i got

  • 0

I have the following script inside a HTML page:

<script>

function Test(){

alert("i got here");

 var username = document.registration_form.username.value;

 alert(username);

 $.post("checkname.php", { name:  username }, function(data) {

   alert("and here");

   alert(data);

   if (data = "0"){
       alert('That username is already in use, please choose another');
    return false;
   };
   if (data = "1") {
    return true;   
   };

});
};

</script>

I’m trying to get the function test to return true or false if a username is already in my database.

checkname.php contains the following:

<?

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myusername=$_POST['name'];


$sql="SELECT * FROM members WHERE username='".$myusername."'";


$result=mysql_query($sql);


$count=mysql_num_rows($result);


if($count >= 1){
echo "0";
}
else {
echo "1";
}

?>

I’ve tried hardcoding a name and running the PHP and it works fine.

For some reason though when I run Test() the first 2 alerts come through fine, showing me the username enetered, but none of the subsequent alerts appear.

Oooo and jQuery has been added in the header like so:

<script src="create/js/jquery-1.4.4.min.js" type="text/javascript" ></script>
<script src="create/js/jquery-ui-1.8.7.custom.min.js" type="text/javascript"></script>

Any help much appreciated 🙂

  • 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-20T09:43:44+00:00Added an answer on May 20, 2026 at 9:43 am

    First of all, your return statements from the callback to $.post will not return from your Test() function. You should call Test with a callback function that deals with the data from the server, something like this:

    function Test(username, callback) {
      $.post("checkname.php", {name: username}, callback);
    }
    
    Test(document.registration_form.username.value, function(data) {
      if(data == "0") {
        // Do something
      } else {
        // Do something else
      }
    });
    

    Brad is also correct about the comparison – you’re currently assigning “0” to data. You should get the alerts though, I think, even with the other errors. Maybe you need the absolute path to the checkname.php script? E.g. “/checkname.php” (note the slash)?

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

Sidebar

Related Questions

I have put together the following mootools script window.addEvent('domready', function() { var shouts =
I have the following markup inside a master page <html xmlns=http://www.w3.org/1999/xhtml > <head runat=server>
I have the following script, where the first and third document.writeline are static and
I have the following jquery code that I've embedded inside of a View: $(document).ready(
I have the following in an aspx page inside a body tag: <form id=Form1
I have the following javascript to embed a flash in my page.tpl.php <script type=text/javascript>
I have the following script. It replaces all instances of @lookFor with @replaceWith in
i have the following script import getopt, sys opts, args = getopt.getopt(sys.argv[1:], h:s) for
In tcsh , I have the following script working: #!/bin/tcsh setenv X_ROOT /some/specified/path setenv
I have the following shell script registered in my Login Items preferences but it

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.