Click here to Skip to main content
Licence CPOL
First Posted 11 Apr 2007
Views 21,491
Downloads 140
Bookmarked 19 times

User Name Availability Using Ajax and ASP

By | 8 Sep 2008 | Article
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)

About the Author

AdityaSuley

Software Developer (Senior)
Headstrong LLC
India India

Member

Senior Developer.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalformat broken Pinmvptoxcct23:32 11 Apr '07  
GeneralRe: format broken PinmemberAdityaSuley0:07 12 Apr '07  
GeneralRe: format broken Pinmvptoxcct0:09 12 Apr '07  
GeneralRe: format broken PinmemberAdityaSuley18:25 12 Apr '07  
GeneralRe: format broken Pinmemberrodrigosor2:49 27 Apr '07  
GeneralRe: format broken Pinmvptoxcct3:05 27 Apr '07  

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.

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