Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

User Name Availability Using Ajax and ASP

1.89/5 (5 votes)
8 Sep 2008CPOL1 min read 1   242  
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)