<script type="text/javascript">
function checkUser(){
var ajaxRequest ;
if(window.XMLHttpRequest)
{
ajaxRequest = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
alert("Browser error");
return false ;
}
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState==4)
{
var area =document.getElementById('form');
area.innerHTML=ajaxRequest.responseText ;
}
}
var name = document.myform.name.value ;
ajaxRequest.open("GET","checkusere.php"+"name="+name,true)
ajaxRequest.send(null);
}
<head>
<body>
<form name='myform'>
Please insert your name:<input type='text'name='name'><br>
<input type='button' onclick='checkUser()' value='click me'>
</form>
<div id='form'></div>
</body>
</html>
==============================================================
//file checkuser.php
<?
mysql_connect('localhost','root','your password');
ysql_select_db('your data base');
sql="select username from user where username like '$name' ";
$result=mysql_query($sql);
if($result){
Sorry! this name has aready exits.
}else {echo you can use this name.}
?>
Date :
19 พ.ย. 2550 13:40:33
By :
sawasdee
No. 2
Guest
-*- ใช้ ajax น้องเค้าจะไม่งงเหรอคับ
Date :
19 พ.ย. 2550 17:53:44
By :
Tomato Project # 1
No. 3
Guest
ไม่งงหรอกครับน้องเค้าขอ code มาไม่ได้ขอแนวทางหรือพยายามหาความรู้
ขอแก้ syntax หน่อยครับ
<?
mysql_connect('localhost','root','your password');
mysql_select_db('your data base');
$sql="select username from user where username like '$name' ";
$result=mysql_query($sql);
if($result){
echo"Sorry! this name has aready exits.";
}else {echo "you can use this name.";}
?>