Developers Tutorials in ASP, PHP, ASP.NET, JSP, Python AND Ruby
 
Classic ASP ASP.NET PHP/mySQL JSP/Servlet Ajax Ruby Python Cold Fusion Perl Grails
  Home |   Topics |   Search |   Login / Register |   Rss Feeds


Topics
» Classic ASP
» ASP.NET
» PHP/mySQL
» JSP/Servlet
» Ajax
» Ruby
» Python
» Cold Fusion
» Perl
» Grails
Search news
Search for:

My Account
Email:

Password:


Register
Forgot password?

Listed in ASPin.com




site statistics



Ajax powered ASP user signup form



This sample application lets your clients to check username before contiue to fill the  sign up form. Rest of the code is a simple user signup form and stores the information to SQL Server.

Let's examine all code:

usernamecheck.js

var xmlHttp

function checkUsername(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
    var url="check.asp";
    url=url+"?username="+str;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("userNameControlValue").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

If you look at signup form page, you'll see that I have entered a simple ajax code. When a client hit "Check Availability" button, script send username input value to checkUsername function. Our Ajax/JavaScript codes are stored in usernamecheck.js file. And send value to check.asp file and retrieves the result. stateChanged function passes returned message form check.asp to our sign up form.
All we do with Ajax is send to check.asp file user input value and write message inside userNameControlValue div tag.


<%
    if request.form("formsubmit") = "true" then
    set cn= server.CreateObject("adodb.connection")
    cn.open "Provider=SQLOLEDB;Data Source=.\SQLEXPRESS;database=gnews2;uid=sa;pwd=123456;"

    uname = replace(trim(Request.QueryString("username")), "'", "''")
    password = replace(trim(Request.QueryString("password")), "'", "''")
    password1 = replace(trim(Request.QueryString("password1")), "'", "''")
    Dim strMsg
    Dim errs
    errs = 0
    if len(uname) < 6 then
        errs = errs + 1
        strMsg = strMsg & "The username must contain at least six characters.
"
    elseif len(uname) > 25 then
        errs = errs + 1
        strMsg = strMsg & "The username must contain at most twentyfive characters.
"
    end if

    if len(password) < 6 then
        errs = errs + 1
        strMsg = strMsg & "The password must contain at least six characters.
"
    elseif len(password) > 10 then
        errs = errs + 1
        strMsg = strMsg & "The password must contain at most ten characters.
"
    end if
    if errs = 0 then
    set r = cn.execute("select uname from  users where uname like '"& uname &"'")
    if not r.eof then
        errs = errs + 1
        strMsg = strMsg & ""& uname &" is not available. Please try a different username.
"    
    end if    
    end if
    if errs = 0 then
        cn.execute("insert into user (uname, pword) values ('"& uname &"', '"& password &"');")
        strMsg = "Your account created!
"
        
        ' here you can create sessions and redirect user to user pages.
       
    end if

    end if
%>


    User Sign Up Form
   
   
        td, input { font:11px arial; }
   
   


   

   
   
   
   
       
   
   
   
       
   
   
   
       
   
   
   
       
   
   
   
       
   
   
   
 
    <%
        response.write strMsg
    %>   
   

   
Username:
   
   
   
Password:
   
   
Password (retype):
   
   
 

   




Check.asp file is a simple ASP code and checks username input value. SQL query searches database and returns username is available or not.

<%
        username = replace(trim(Request.QueryString("username")), "'", "''")
        if len(username) > 0 then
        set cn= server.CreateObject("adodb.connection")
        cn.open "Provider=SQLOLEDB;Data Source=GZ\SQLEXPRESS;database=gnews2;uid=sa;pwd=123456;"
        sql = "select uname from  users where uname like '"& username &"'"
        set r = cn.execute(sql)
        if r.eof then
            response.write "
Username "& username &" is available."

        else
            response.write "
Username "& username &" is not available. Please try a different username"   

        end if
        r.close
        set r = nothing
        cn.close
        set cn = nothing
        else
        response.write "
Please type your username."

        end if
%>




You may edit all source simply and can be used in a real application. ASP is enough suitable to work with Ajax.

Download all code.

Happy Coding





More latest headlines in Ajax
This sample application lets your clients to check username before contiue to fill the  sign up form. Rest of the code is a simple user signup form and stores the information to SQL Server.







What's New
Ajax powered ASP user signup form
Cross domain access policy in Silverlight applications
LINQ the Bridge between the world of Objects & the world of Data
Dynamically creating DeepZoom composition
DoubleAnimation Basics with Silverlight Application
Display Paged Recordset Data
GetRows VBScript Class - Part III: Paging the results
ASP & MySQL Record Paging
Ways to get Alphabetical Paging for your ASP scripts
Sorting Database Records

Most Popular
How to embed UpdatePanel in a Repeater
Mark a GridView row, and move it with the up and down key
ASP & MySQL Record Paging
Cross-Page Posting Example
Implementing Cross-Domain Cookies
Auto-upload using IE+ADO without user interaction
How to modify expire date of a cookie
Ways to get Alphabetical Paging for your ASP scripts
GetRows VBScript Class - Part III: Paging the results
Dynamically creating DeepZoom composition

Copyright © 2009 Powered by GNews Publisher Positive. All rights reserved. Contact Us - Load Time: 0.50 second(s)