here my problem is ,when i check if the username is exist in the DB ,there must have one option to re enter it.In this program when i make an attempt to reenter the username.it will clear all the other contents also(emailid).P lease help me to locate the cursor in username field only and do not change the other fields.
Code:
<html>
<script language = "Javascript" type="text/javascript">
/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
{
alert("1.Invalid E-mail ID")//@not come,first char is @ or len @ is last char
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("2.Invalid E-mail ID")
return false
}
if (str.indexOf(at,(lat+1))!=-1)//when more @ come together
{
alert("3.Invalid E-mail ID")
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)//@. or .@ not come tgthr or
{
alert("4.Invalid E-mail ID")
return false
}
if (str.indexOf(dot,(lat+2))==-1)//if . is not come after @abc eg:meg@abc(is false)meg@ad(false)meg@gmail.com(correct)
{
alert("5.Invalid E-mail ID")
return false
}
if (str.indexOf(" ")!=-1){
alert("6.Invalid E-mail ID")
return false
}
return true
}
function ValidateForm(){
alert("fn");
var emailID=document.frmSample.txtEmail
var name=document.frmSample.txtname
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your e mail")
emailID.focus()
return false
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
if ((name.value==null)||(name.value=="")){
alert("Please Enter your name")
emailID.focus()
return false
}
return true
}
</script>
<?php
$result="";
$sql1="";
include_once("includes/config.php");
$tableobj=new dataBase();
if(isset($_POST['Submit']))
{/*value="<?php if($_REQUEST['name']){ echo $_REQUEST['name']; } ?>"*/
$name=mysql_escape_string(trim($_POST['txtname']));
$emailid=trim($_POST['txtEmail']);
echo $name;
$result="SELECT * FROM admin WHERE (Admin_username)='".$name."'";
$row=$tableobj->selectQry($result);
$p=count($row);
echo $p;
echo"******";
$no=0;
for($i=0;$i<count($row);$i++)
{
$no++;
echo $no;
echo"#######";
}
if($no==0)
{
$sql1="INSERT INTO admin(Admin_name,Admin_username,Admin_passwd,email_id) VALUES('kamal','".$name."','megha','".$emailid."')";
if(!mysql_query($sql1,$con))
{
echo"error".mysql_error();
}
mysql_close($con);
}
if($no>0)
{
echo"username existing";
//header("location:email.php");
//exit();
}
}
?>
<body>
<form name="frmSample" method="post" action="email.php" onSubmit="return ValidateForm()">
<p>Enter name :
<input type="text" name="txtname" >
</p>
<p>
</p>
<p>Enter an Email Address :
<input type="text" name="txtEmail">
</p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
Comment