This file requires the introduction of two file Jquery.js (jquery framework files) and grade.js (validated individual files).
The following input is used to enter the user name, and id= "Gradeinfo" is used to display the hint information.
grade.htm
Copies code code as follows:
<input type= "text" size= "6" name= "name" id= "name"/><font color= "Red" >* </font>
<span id= "Gradeinfo" ></SPAN>
When the user enters the information, enter the validation link to see how our verification grade.js is written.
Grade.js
Copies code code as follows:
/**
* Verify user name is duplicated JS
*
* @name grade.js
* @author Jason<msn:x334@ey Ou.com>
* @use Verify that the username exists
* @todo
*/
$ (document). Ready (function () {
checkconfirm ();
});
//Verify that the user name exists
function checkconfirm () {
$ ("#name"). blur (function () {
var gradename = $ (this). Val ();
var changeurl = "gradeadmin.php tutorial? action=check&gradename=" +gradename;
$.get (changeurl,function (str) {
if (str = ' 1 ') {
$ ("#gradeinfo"). HTML ("<font color=" Red "> The username you entered exists! Please re-enter! </font> ");
}else{
$ ("#gradeinfo"). HTML ("");
}
})
return false;
})
The above JS file, I only explain a few more key places.
1. $ ("#name"). The meaning of Blur is to trigger an action when the form with ID name in the grade.htm is finished.
2, $ (this). Val () means to get the value in the form with ID name.
3, $.get (str) meaning is: After running Ajax, Changeurl is to connect the program address, STR is the program
The display structure that is obtained after the calculation is completed.
4. $ ("#gradeinfo"). The meaning of HTML is to write an HTML file to a label with an ID of gradeinfo. A label with an ID of gradeinfo means
Grade.htm in the ID of the Gradeinfo, the display of the content will appear again in the location of the tag.
Then look at the gradeadmin.php of the calculation form.
gradeadmin.php
Copy Code
Copy code code as follows:
if ($frm _action = = ' Check ')
{
$gradename = $_get[' gradename '];
$gradeadminobj = new Services_gradeadmin ($DB);
According to $gradename to determine whether the database tutorial exists in the user name filled in, if there is a return of 1, if
Does not exist returns 0, this return value is passed to Grade.js.
$gradecheck = $gradeadminobj->getgradebyname ($gradename);
if (Is_numeric ($gradecheck)) {
echo ' 1 ';
}else{
echo ' 0 ';
}
Exit ();
}
This is the question of whether or not the user name exists when the user registers