Javascript almost not working On live check username validation

Hello every body, i am developing site and i have some problem about javascript, I looking way to make solve this issue but i tired to fine it on internet, every i type some username for check, it always get same result, i type any username or word it was got same result as " username is taken" , anybody can help me solve this?

Welcome, @irawantand. We can’t really help you unless you give us more information to go on. Can you post the code you are working on that is giving you this problem?

1 Like

there is my code
in server side

<script>
function checkAvailability() {
   var username_tocheck = $("#username").val(); //Probably you want to validate it before you send
   $.ajax({
           url: "check_username.php", // Try full url too
           data: { username :  username_tocheck },
           method: "POST",  //  POST | GET
           Type: "html", // xml,json,script,html
           beforeSend: function() {
                 $("#loaderIcon").show();
           },
           success:function(data){
                 $("#user-availability-status").html(data);
                 $("#loaderIcon").hide();
           },
           error:function ( jqXHR, textStatus ){
                alert("error: " + textStatus);
                console.log("error: " + textStatus);
           }
   });
}
</script>

in check_username.php

<?php
// This is a sample code in case you wish to check the username from a mysql db table
mysql_connect('localhost', 'root', 'pass');
mysql_select_db('test123');
if(isset($_POST['username'])) {
$username = mysql_real_escape_string($_POST['username']);

$sqlqt="select * from member where username ='$username'";
$numresultsqt=mysql_query($sqlqt) or die(mysql_error());
$numrowsqt=mysql_num_rows($numresultsqt);


if ($numrowsqt > 0) {

  echo "<font color='FF0000'>Username Has Been Use, Try Another.</font>";

} else {

  echo "<font color='228B22'>Congratulation, Username Available.</font>";
}
}
 ?>

in my form

<tr>
  						<td>Username</td>
  						<td>:</td>
  						<td><input type="text" id="username" name="username" class="form-control" placeholder="Username" autocomplete="off" onkeyup="this.value = this.value.toUpperCase();" onBlur="checkAvailability()"></td>
  					</tr>
            <tr><td></td><td></td><td><div id="user-availability-status"></div></td></tr>
            <tr><td height="20"></td>
            </tr>

what’s wrong with my code?
even I type in field it always get “Username Has Been Use, Try Another”

Thanks for your attention

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.