AJAX Registration Page

Posted By Venu Thomas

Here AJAX Registration Page with HTML & Javascript. Checking username, length, password match..

live_previewLive Preview downloadDownload

$(document).ready() :

The most commonly used command in jQuery is $(document).ready(). It makes sure code is executed only when a page is fully loaded. We often place code blocks inside this $(document).ready() event.

?View Code JAVASCRIPT
 
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
 
// Your Code
 
$(document).ready(function()
 
{
 
// Put all your jQuery goodness in here.
 
}

Checking Username Length:

When guest types something in Username field less than 3 characters and focus move from it to next field. An error will be occurred .

username3

?View Code JAVASCRIPT
 
usr = $("#txt_username").val();
 
if(usr.length >= 3) //checking username length
{
	// Checking username code here..
}
 
else
{
	//Error Message code here..
 
}

Chekcing Username:

When guest types something in Username field greater than or equal 3 characters and focus move from it to next field Then, A waiting message will be displayed with small image as loader.gif.

checkingusername

?View Code JAVASCRIPT
$("#div_status").html('<img src="loader.gif" align="absmiddle">&nbsp;Checking username....');

If Username is available:

if username available from database. Ajax will display like this, Otherwise, An error will be occurred.

usernameready

?View Code JAVASCRIPT
	$.ajax({
    type: "POST",
    url: "check_username.php",
    data: "username="+ usr,
    success: function(msg){
   $("#div_status").ajaxComplete(function(event, request, settings){
 
	if(msg == 'OK')
		{
			// If the username available, goes here.
		}
		else
		{
			//If the username not available, goes here.
		}

Checking Password:

When guest types something in password field less than 3 characters and focus move from it to next field. An error will be occurred .

password3

?View Code JAVASCRIPT
 
var str_confirm_password = $("#txt_confirm_password").val();
 
if(str_password.length  >=3)
{
	// Checking Password match code here..
}
else
{
	// Error message code here..
}

Checking Password Match:

When guest types something in Password & Confirm Password fields, and focus move from it to next field. Then, it will check value of both fields. If both field’s value are not same then, an error will be displayed.

If not match

passwordnotmatch

If match

passwordready

?View Code JAVASCRIPT
var str_password = $("#txt_password").val();
var str_confirm_password = $("#txt_confirm_password").val();
 
if(str_password!=str_confirm_password)
{
	// If not match, goes here,
}
else
{
	//If match, goes here.
}

“Sign Up Now” Button :

When guest push “Sign Up Now!” button. It goes to next page .

?View Code JAVASCRIPT
function fn_onclick() {
	if(str_status == "OK" && str_pwd_status =="OK" && str_password != '' && str_confirm_password != '' )
	{
		$("#div_msg").html('<div id="logged_in"> <br />' +
    	 'Thanks for Registering <br />' +
   		  '<img align="absmiddle" src="loader_bar.gif">' +
    	 '<br /> Please wait while we redirect you to welcome page...</div>');
 
		setTimeout('go_to_next_page()', 4000);
	}
}
 
function go_to_next_page()
{
	window.location = 'welcome.html';
}

.removeClass() & .addClass() functions :

.removeClass() & .addClass() functions are used for add styles into username & password fields. In code, ‘css_ok’ & ‘css_error’ regarding from ‘style.css’ . For instance these functions show the box green if the values entered in the boxes are correct & otherwise red color

.

?View Code JAVASCRIPT
<link rel="stylesheet" type="text/css" href="style.css" />
 
	// Your code here..
 
$("#txt_username").removeClass('css_ok');
$("#txt_username").addClass("css_error");

In style.css,

.css_ok
{
border: 1px solid green;
color: #333333;
}
.css_error
{
border: 1px solid #AC3962;
color: #333333;
}

live_previewLive Preview downloadDownload

Tags: ,

  •  
  • Share with others:

    Thanks for visiting us! If you enjoyed these icons please feel free to share them! Or if you want to know what's going on with WiseCodes.com, follow us!

    Leave a Reply

    Anti-Spam Protection by WP-SpamFree

    Locations of visitors to this page eXTReMe Tracker