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
vandana rajuvandana raju 

call apex method on keypress event

Hello
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
thanks
vandana
 
LBKLBK
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:form>
		<apex:actionFunction action="{!validateEmail}" name="fnValidateEmail">	
		</apex:actionFunction>
		
		<apex:inputField value="{!contact.Email}" onblur="fnValidateEmail" />
	</apex:form>
</apex:page>

/*****Controller*****/
public class myController {
	public PageReference validateEmail() {
		//do your validation here
		return null;
	}
}
Hope this helps.
 
sunny522sunny522
Hey Vandana Raju,
     Here is simple example to call action:function
http://salesforceglobe4u.blogspot.com/2017/05/actionfunction-in-salesforce.html
Let me know if u need any further help.