Ajax Example
Screen shot
HTML Page

<html>
<head>
<script type=\"text/javascript\" src=\"ajax.js\">
</script>
<style type=\"text/css\">
<!--
.style1 {
color:#FF3300;

}
-->
</style>
</head>
<body>
<table width=\"309\" height=\"211\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td height=\"39\" colspan=\"2\" align=\"center\">Create User Account </td>
</tr>
<tr>
<td>User ID</td>
<td><input name=\"userid\" type=\"text\" onKeyUp=\"display(this.value)\">
<div class=\"style1\" id=\"showuser\"></div></td>
</tr>
<tr>
<td>User Password</td>
<td><input name=\"userpassword\" type=\"text\"></td>
</tr>
<tr>
<td>User Name </td>
<td><input name=\"username\" type=\"text\" id=\"username\"></td>
</tr>
<tr>
<td>Email</td>
<td><input name=\"email\" type=\"text\" id=\"email\"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name=\"btnsubmit\" type=\"submit\" value=\"Submit\"></td>
</tr>
</table>
</body>
</html>

Javascript Page (save as ajax.js)

var XMLHttpRequestObject=false;

function display(user)
{
if(window.XMLHttpRequest)
{
XMLHttpRequestObject=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
XMLHttpRequestObject=new ActiveXObject(\"Microsoft.XMLHTTP\");
}

XMLHttpRequestObject.onreadystatechange=function()
{
if (XMLHttpRequestObject.readyState==4 && XMLHttpRequestObject.status==200)
{
document.getElementById(\"showuser\").innerHTML=XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.open(\"GET\",\"users.php?id=\"+user,true);
XMLHttpRequestObject.send();
}

PHP Page(save as users.php)

<?php
$con=mysql_connect(\'localhost\',\'root\',\'\') or die(\'Mysql not connected\');
mysql_select_db(\'users\',$con) or die(\'DataBase not connected\');

$id=$_GET[\"id\"];
$query=\"select * from user_login WHERE user_id = \'\".$id.\"\'\";
$result = mysql_query($query);
$num=mysql_num_rows($result);
if($num>0)
echo \"User already Exist\";
?>

DataBase

--
-- Database: `users`
--

-- --------------------------------------------------------

--
-- Table structure for table `user_login`
--

CREATE TABLE IF NOT EXISTS `user_login` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(100) NOT NULL,
`user_password` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `user_login`
--


INSERT INTO `user_login` (`id`, `user_id`, `user_password`) VALUES
(1, \'shishir012010\', \'bcamca\'),
(2, \'ravi2010\', \'9953891928\');