function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ravi BRavi B 

I want to check if username is availble or not when i am entered in username texbox by using apex and ajax

Hi
  i am new to salesforce i want to please give a sample code for this,please help me out
  for reference i have attacthed url please check
  like this :http://youhack.me/2010/05/04/username-availability-check-in-registration-form-using-jqueryphp/

please share me code if any one have
Ramu_SFDCRamu_SFDC
Here is the sample code

VF:

<apex:page controller="checkavailability">
<apex:pageBlock >
<apex:form >
<apex:outputtext value="Username"/>&nbsp;&nbsp;
<apex:inputText id="username" value="{!username}"/>
<apex:outputpanel id="ajax">
<apex:commandButton id="checkavailability" action="{!CheckAvailability}" value="Check Availability"  rerender="ajax" status="renderstatus"/>
<apex:outputtext id="status" value="{!status}" />
<apex:actionStatus id="renderstatus" startText="Loading..." />
</apex:outputpanel>
</apex:form>
</apex:pageBlock>
</apex:page>

CONTROLLER :

public class checkavailability {
    public string status{get; set;}
    public String username { get; set; }
    public PageReference CheckAvailability() {
        if(username==''){
            status='enter username';
            return null;
        }
        else{
            list<user> users=[select id from user where username=:username];
            if(users.size()>0){
                status='Not Available';
            }
            else{
                status='Available';
            }
            return null;
        }
    } 
}

Hope this helps!!