+ Start a Discussion
vandana rajuvandana raju 

call apex method on keypress event

I having a custom object C1 with fields like name,email and mobile number.On an visualforce page I will enter the values and save the data.This part is fine with me.
Now my requirement is when I enter email in <apex:inputfield> say on keypress event I should be able to call an server side method in apex controller.
This method will check if the email already exists in object. If it exists then some action needs to be taken.

Please anybody any help will be greatly appreciated
Hi Vandana,

OnKeyPress may not be the suitable event for you to validate the Email address.

You have to use onblur event of the <apex:inputfield> component and setup an apex:actionFunction to make a callback to your APEX method.

Your code will approximately look like this.
VF Page
<apex:page controller = "myController">
		<apex:actionFunction action="{!validateEmail}" name="fnValidateEmail">	
		<apex:inputField value="{!contact.Email}" onblur="fnValidateEmail" />

public class myController {
	public PageReference validateEmail() {
		//do your validation here
		return null;
Hope this helps.
Hey Vandana Raju,
     Here is simple example to call action:function
Let me know if u need any further help.