How to check whether the Username is available or not in JqeryAjax and PHP?
1) CheckUserName.php
<script src="jquery-latest.js" type="text/javascript"></script>
<style type="text/css">
.no{color:red;}
.yes{color:blue;}
</style>
<script src="jquery-latest.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$('#Uname').blur(function(){
var form_data = {
querName:"queryVal",
Uname:$(this).val()
};
$.ajax({
type:"POST",
url:"chechUserName.php",
data:form_data,
success:function(result)
{
$('#message').html(result);
}
});
});
});
</script>
<form method="post" action="#">
<table>
<tr>
<td>Username</td><td><input type="text" name="Uname" id="Uname"></td><td><div id="message"></div></td>
</tr>
</table>
</form>
2) chechUserName.php
<?php$querName = $_REQUEST['querName'];
if($querName == 'queryVal')
{
$querVal = $_REQUEST['Uname'];
check_value($querVal);
}
function check_value($querVal)
{
$arrayVal = array("sairam","manoj","balaji","govind");
if(in_array($querVal,$arrayVal))
{
echo "<span class='no'> $querVal is not available </span>";
}
else
{
echo "<span class='yes'> Available </span>";
}
}
?>
Comments
Post a Comment