<form id= "Form1" onsubmit= "return false;" >
<table id= "Login-table" >
<tr>
<TD width= ">" No.:</td>
<td><input class= "textbox" type= "text" style= "width:160px;" id= "txtUserName"
Maxlength= "9" onblur= "Checkusername ()" onclick= "$.trim (this.value)"/><span></span>
</td>
</tr>
<tr>
<TD width= "" > Password:</td>
<td><input class= "textbox" type= "Password" style= "width:160px;" id= "Txtuserpwd"
Onblur= "Checkuserpwd ()" onclick= "$.trim (this.value)"/><span></span>
</td>
</tr>
<tr>
<TD width= "Up" > Verification Code:</td>
<td><input class= "textbox" type= "text" style= "width:160px;" maxlength= "5"
Id= "Txtcheckcode" onblur= "Checkcheckcode ()" onclick= "$.trim (this.value)"/><span>
</span>
</td>
</tr>
<tr>
<TD width= "></td>"
<td><div style= "color: #808080;" > characters in input, case insensitive </div><br/>
<a href= "#" id= "Change_image" > can't see Clearly, change a </a></td>
</tr>
<tr>
<TD width= "></td>"
<td><input type= "image" Src= "app_themes/images/btn_login.jpg" id= "Btnlogin"
alt= "Login Now" style= "border:0;" /></td>
</tr>
</table>
</form>
<script language= "javascript" type= "Text/javascript" >
$ (document). Ready (function () {
//Verification Code update
$ (' #change_image '). Click (
Function () {
$ (' #imgCheckCode '). attr (' src ', ' checkcode.aspx? ') +math.random ());
});
//Key code
$ ("#btnLogin"). Click (function () {
if (checkusername () && checkuserpwd () && Checkcheckcode ())
{
var data = {
UserName: $ (' #txtUserName '). Val (),
Userpwd: $ (' #txtUserPwd '). Val (),
Checkcode: $ (' #txtCheckCode '). Val ()
};
//Submit data to Login.ashx page processing
$.post ("Ajax/login.ashx", data,function (Result) {
if (result = = "1")//Login successful
{
Alert ("Login successful! You can do something else! ");
//Close the simulation window
Window.parent.window.jBox.close ();
}
Else if (result = = "2")//Authenticode error
{
$ (' #txtCheckCode '). Next ("span"). CSS ("Color", "red"). Text ("*
Verification code Error ");
}
Else
{
Alert ("Login failed! Please try again ");
}
});
}
Else
{
Checkusername ();
Checkuserpwd ();
Checkcheckcode ();
}
});
});
Check the UserName
function Checkusername ()
{
if ($ ("#txtUserName"). Val (). length = = 0)
{
$ ("#txtUserName"). Next ("span"). CSS ("Color", "red"). Text ("* User name is not empty");
return false;
}
Else
{
var reg =/^\d{9}$/;
if (!reg.test ($ (' #txtUserName '). Val ()))
{
$ (' #txtUserName '). Next ("span"). CSS ("Color", "red"). Text ("* Correct format
such as: 030602888 ");
return false;
}
Else
{
$ ("#txtUserName"). Next ("span"). CSS ("Color", "red"). Text ("");
return true;
}
}
}
Check the PWD
function Checkuserpwd ()
{
if ($ (' #txtUserPwd '). Val (). length = = 0)
{
$ (' #txtUserPwd '). Next ("span"). CSS ("Color", "red"). Text ("* Password is not empty");
return false;
}
Else
{
$ (' #txtUserPwd '). Next ("span"). CSS ("Color", "red"). Text ("");
return true;
}
}
Check the check code
function Checkcheckcode ()
{
if ($ (' #txtCheckCode '). Val (). length = = 0)
{
$ (' #txtCheckCode '). Next ("span"). CSS ("Color", "red"). Text ("* Verification code is not empty");
return false;
}
Else
{
$ (' #txtCheckCode '). Next ("span"). CSS ("Color", "red"). Text ("");
return true;
}
}
Ajax Authentication Login Registration