Introduction
This code explain the procedure to check the availability of username in database records. Username is used as identifier for members so it must be unique. Using this code user can check the availability of username from current page.
If username specified by new user already exists in records then message is displayed saying 'this username already exists'.
If username does not exists in records then message is displayed saying 'congratulations you got it'.
This code can be used in all registration pages where username or any other criteria fed by user is required to be unique. '
Using the code
Simply unzip the folder and use the code. Code is in running state.
AJAX is used to check the records in database. Using AJAX we can run any other ASP from from current page.
Step for using code are explained below:
Step 1: Check if user have provided input properly which will be the condition for accessing data from database. For e.g. if we take username availability program then we check whether user have specified the username or not which is to be compared with existing usernames in the database.
Step 2: Create a new XMLHTTP object with following syntax:
var httpob=new ActiveXObject("Microsoft.XMLHTTP")
Step 3: Open this object with Open() method which take three arguments. The first argument defines which method to use when sending request(GET or POST). Next argument specifies the file name which contains the server-side script. We can pass parameters from current page to that file. And the last argument specifies that the request should be handled asynchronously. While opening object file for communication between current page and page accessing database is defined. We can pass the parameters also to that file.
As shown below check.asp file contains server-side script which is accessed from current page and one parameter 'username' is passed. In username parameter we assign the value which will be used as condition for accessing database. Here username is assign to Id given by user.
a=document.form1.username.value
httpob.open("POST"," check.asp?username=" + a ,false);
In check.asp file, username's value is fetched from browser using request.querystring and compared with existing data in database.
If eof file is encountered means that username was not found in the existing records then message is printed saying "This username is available" else Message is printed saying "This username already exists"
Step 4: httpob.send() – A request is send to the server to execute the check.asp file
Step 5: ab1=httpob.responseText – In one array named ab1 object's response text is fetched. (Note: Response text will be the same text which was printed on check.asp file)
Step 6: Alert(ab1) – This message will confirm whether particular username is available or not.
Points of Interest
With small changes this can code can be used for other coding purposes.