Mình có 3 trang thế này
Trang ajax.js
function chekformreg(url)
{
if(document.getElementById)
{
var x=(window.ActiveXObject)?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
}
if(x)
{
x.onreadystatechange=function()
{
if(x.readyState==4&&x.status==200)
{
if(x.responseText == "false")
{
alert('khong phai email');
}
}
}
x.open("GET",url,true);
x.send(null)
}
}
function chek(yeucau, giatri)
{
chekformreg('checkform.php?yeucau='+yeucau+'&giatri='+giatri);
}
Trang index.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<script type="text/javascript" language="javascript" src="ajax.js">
</script>
<body>
<form name="dangky" action = "" method="post">
Nhập vào Email
<input maxlength="42" name="emaildangky" id="emaildangky" class="input" size="45" type=
"text" onBlur="chek('email', 'this.value')" /> <br/><div id="mess"></div>
</form>
</body>
</html>
Và trang checkform.php
<?php
$value = $_GET['giatri'];
$request = $_GET['yeucau'];
switch($request)
{
case 'email':
checkemail($value);
}
function checkemail($value);
{
if(ereg("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $value, $regs)) {
echo "true";
} else {
echo "false";
}
}
?>
Mình không biết function chekformreg(url) và function chek(yeucau, giatri) sai hay là cách lấy gián trị onBlur="chek('email', 'this.value')" sai mà nó không gọi được đến trang checkform.php, nó chỉ gọi được đến hàm chek(yeucau, giatri) lúc này là chek('email', 'this.value') rồi đứng im re.
Mình muốn làm là lấy giá trị trong từng input bằng ajax, gửi đến trang checkform.php, tùy vào yêu cầu là gì trong hàm check() sẽ gọi hàm tương ứng trong trang checkform.php. Các bác giúp em với.
Tác giả:hello
