Hello all, i'm building a register page for my forum
my problem faced is i can't disable the DAMN Button! while the
user input duplicate or wrong format ! Pls help me! T^T
<?php
include 'dbconn.php';
include 'Header.php';
?>
<form name="frmRegisteration" action="Register.php" method="post" onSubmit="return DataValidator()">
<?php
$name = $_POST['txtname'];
$password = $_POST['txtpasswd'];
$email = $_POST['txtemail'];
if(isset($name,$password,$email))
{
echo "Inserting to database <br />";
$qry_insertauthor = "INSERT INTO author (user_name,passwd,email) VALUES ('".$name."','".$password."','".$email."')";
$arr_insertauthor = mysql_query($qry_insertauthor);
}else{ echo "Not inserted! <br />";}
?>
<div id="Register" style="margin-top:10px; "><table width="100%">
<tr><td width="15%"><em>Name :</em><br /></td><td><input name="txtname" id="regName" size="25" onKeyUp="UserValidate(this.value)" onBlur="Disablebutton(document.getElementById('txterror').value)"/>
<label id="txterror">* Please Enter your name here</label></td></tr>
<tr><td><em>Password :</em><br /></td><td><input type="password" name="txtpasswd" id="regPasswd" size="25" maxlength="15" /></td></tr>
<tr><td><em>E-mail :</em><br /></td><td><input name="txtemail" id="regEmail" size="25" onKeyUp="emailValidate(this.value)" />
<label id="txterror2" on>* Please Enter your email here</label></td></tr></table>
<em> </em><input type="submit" name="btnRegister" id="regbtnRegister" value="Register" disabled/>
</div>
</form>
<? include'Footer.php'; ?>
function DataValidator(){
var errormsg ="Data Incomplete! Please Enter Your ";
if(((notEmpty(document.getElementById("regName")))==false)||((notEmpty(document.getElementById("regPasswd")))==false)||((notEmpty(document.getElementById("regEmail")))==false)){
if((notEmpty(document.getElementById("regName")))==false)
{ var str="- User Name";
errormsg= errormsg+str;}
if((notEmpty(document.getElementById("regPasswd")))==false)
{ var str="- Password";
errormsg= errormsg+str;}
if((notEmpty(document.getElementById("regEmail")))==false)
{ var str="- E-mail ";
errormsg= errormsg+str;}
alert(errormsg);
return false;
} else{
alert("Thank you for your cooperation! Data Inserted !");
return true;}
}
function PostThreadValidation(){
var errormsg ="Data Incomplete! Please Enter Your ";
if(((notEmpty(document.getElementById("req2")))==false)||((notEmpty(document.getElementById("category")))==false)||((notEmpty(document.getElementById("req1")))==false)){
if((notEmpty(document.getElementById("req2")))==false){
var str="- Title";
errormsg= errormsg+str;}
if((notEmpty(document.getElementById("category")))==false){
var str="- Category";
errormsg= errormsg+str;}
if((notEmpty(document.getElementById("req1")))==false){
var str="- Content";
errormsg= errormsg+str;}
alert(errormsg);
return false;
} else{
alert("Thank you for your cooperation! Data Inserted !");
return true;}
}
function emailValidator(elem){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
return true;
}else{
return false;
}
}
function notEmpty(elem){
if(elem.value.length == 0){
return false;
}else{
return true;
}
}
function UserValidate(name)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
result=xmlhttp.responseText;
var error = " * The name were duplicated! Please Re-Enter another name.";
document.getElementById("txterror").innerHTML= result;
}
}
xmlhttp.open("GET","RegisterAJAX.php?Name="+name,true);
xmlhttp.send();
}
function emailValidate(email)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txterror2").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","RegisterAJAX.php?Email="+email,true);
xmlhttp.send();
}
function Disablebutton(errortxt){
alert("work!~");
var str1 = " * The name were duplicated! Please Re-Enter another name.";
if(errortxt.match(str1)){
alert("not match");
document.getElementById("regbtnRegister").disabled = true;
}
else
{
alert("match");
document.getElementById("regbtnRegister").disabled = false;
}
}
<?php include("dbConn.php") ?>
<?php
if(isset($_GET["Name"])){
$name=$_GET["Name"];
$qry_getname = "SELECT COUNT(user_name) FROM author WHERE user_name='".$name."'";
$arr_getname = mysql_query($qry_getname);
$result = mysql_fetch_assoc($arr_getname);
if($result['COUNT(user_name)'] >=1)
{echo " * The name were duplicated! Please Re-Enter another name.";
}else{ echo " * Valid User Name.";}
}
else if(isset($_GET["Email"])){
$email=$_GET["Email"];
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
$qry_getemail = "SELECT COUNT(email) FROM author WHERE email='".$email."'";
$arr_getemail = mysql_query($qry_getemail);
$result = mysql_fetch_assoc($arr_getemail);
if($result['COUNT(email)'] >=1)
{echo " * The email were duplicated! Please Re-Enter another E-mail Address.";
}else{ echo " * Valid Email.";}
}
else{ echo " * Your Email Format Are Invalid !";}
}
?>