Click here to Skip to main content
15,881,757 members
Articles / Web Development / HTML
Article

User Name Availability Using Ajax and ASP

Rate me:
Please Sign up or sign in to vote.
1.89/5 (5 votes)
8 Sep 2008CPOL1 min read 38.3K   242   19   6
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)


Written By
Software Developer (Senior) Headstrong LLC
India India
Senior Developer.

Comments and Discussions

 
Generalformat broken Pin
toxcct11-Apr-07 23:32
toxcct11-Apr-07 23:32 
GeneralRe: format broken Pin
AdityaSuley12-Apr-07 0:07
AdityaSuley12-Apr-07 0:07 
GeneralRe: format broken Pin
toxcct12-Apr-07 0:09
toxcct12-Apr-07 0:09 
GeneralRe: format broken Pin
AdityaSuley12-Apr-07 18:25
AdityaSuley12-Apr-07 18:25 
GeneralRe: format broken Pin
rodrigosor27-Apr-07 2:49
rodrigosor27-Apr-07 2:49 
GeneralRe: format broken Pin
toxcct27-Apr-07 3:05
toxcct27-Apr-07 3:05 

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

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