Click here to Skip to main content
Click here to Skip to main content
Go to top

User Name Availability Using Ajax and ASP

, 8 Sep 2008
Rate this:
Please Sign up or sign in to vote.
Today everybody want to imporve the performance of a website, as you see on google i.e. the password strength, when we enter any character in password field, password strength is checked i.e weak, strong etc very quickly, so i have added the same functionality for the username availability
Screenshot - screenshot1.gif

Introduction

Today everybody want to imporve the performance of a website, as you see on google i.e. the password strength, when we enter any character in password field, password strength is checked i.e weak, strong etc very quickly, so i have added the same functionality for the username availability

Background

(Optional) Is there any background to this article that may be useful such as an introduction to the basic ideas presented?

Using the code

Today everybody want to imporve the performance of a website, as you see on google i.e. the password strength, when we enter any character in password field, password strength is checked i.e weak, strong etc very quickly, so i have added the same functionality for the username availability

Blocks of code should be set as style "Formatted" like this:

<script language="javascript">
function put(param)
{
  document.form1.username.value=""
  document.form1.username.value=param
  document.getElementById("Available").innerHTML = "";
}

function OnChangedUsername()
{
  if(document.form1.username.value == "")
  {
    document.form1.btnCheckAvailability.disabled = true;
    document.getElementById("Available").innerHTML =""
  }
  else
  {
    document.form1.btnCheckAvailability.disabled = false;
  }
}

function OnCheckAvailability()
{
  if(window.XMLHttpRequest)
  {
    oRequest = new XMLHttpRequest();
  }
  else if(window.ActiveXObject)
  {
    oRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  oRequest.open("POST", "available.asp", true);
  oRequest.onreadystatechange = UpdateCheckAvailability;
  oRequest.setRequestHeader("Content-Type", "application/x-www-  form-urlencoded");
  oRequest.send("strCmd=availability&strUsername=" +  document.form1.username.value);
}

function UpdateCheckAvailability()
{
  if(oRequest.readyState == 4)
  { 
    if(oRequest.status == 200)
    {
      document.getElementById("Available").innerHTML =    oRequest.responseText;
    }
    else
    {
      document.getElementById("Available").innerHTML = "Asychronous Error";
    } 
  }
}

function validate(form1)
{
//****************************************************
if (form1.username.value.length<1)
  {
   alert("Please enter username!");
   form1.username.focus();
   form1.username.select();
   return(false);
  }
else if ((form1.username.value.indexOf("*")!=-1)||
       (form1.username.value.indexOf("!")!=-1)||(form1.username.value.indexOf("@")!=-1)||
       (form1.username.value.indexOf("$")!=-1)||(form1.username.value.indexOf("%")!=-1)||
       (form1.username.value.indexOf(&quot;^")!=-1)||
       (form1.username.value.indexOf("#")!=-1)||(form1.username.value.indexOf("=")!=-1)||
       (form1.username.value.indexOf("-")!=-1)||(form1.username.value.indexOf("[")!=-1)||
       (form1.username.value.indexOf("]")!=-1)||(form1.username.value.indexOf("{")!=-1)||
       (form1.username.value.indexOf("}")!=-1)||(form1.username.value.indexOf("+")!=-1)||
       (form1.username.value.indexOf("~")!=-1)||(form1.username.value.indexOf("?")!=-1)||
       (form1.username.value.indexOf("|")!=-1)||(form1.username.value.indexOf(">")!=-1)||
       (form1.username.value.indexOf("<")!=-1)||(form1.username.value.indexOf(" ")!=-1))
         { 
          alert("Special characters and spaces are not allowed" );
          form1.username.focus();
          form1.username.select();
          return(false);
  }
else if (form1.username.value.length>30)
  {
   alert("Username must be less than thirty characters!")
   form1.username.focus();
   form1.username.select();
   return(false);
  }
}
</script>

Remember to set the Language of your code snippet using the Language dropdown.

Use the "var" button to to wrap Variable or class names in <code> tags like this.

Points of Interest

Did you learn anything interesting/fun/annoying while writing the code? Did you do anything particularly clever or wild or zany?

History

Keep a running update of any changes or improvements you've made here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

AdityaSuley
Software Developer (Senior) Headstrong LLC
India India
Senior Developer.

Comments and Discussions

 
Generalformat broken Pinmvptoxcct11-Apr-07 23:32 
GeneralRe: format broken PinmemberAdityaSuley12-Apr-07 0:07 
GeneralRe: format broken Pinmvptoxcct12-Apr-07 0:09 
GeneralRe: format broken PinmemberAdityaSuley12-Apr-07 18:25 
GeneralRe: format broken Pinmemberrodrigosor27-Apr-07 2:49 
GeneralRe: format broken Pinmvptoxcct27-Apr-07 3:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 8 Sep 2008
Article Copyright 2007 by AdityaSuley
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid