+ Start a Discussion
MJ09MJ09 

Add onChange event handler to an input field in a standard (non-VisualForce) page

I'd like to add an onChange event handler to the standard Contact page layout, so that when the user changes the Contact's first or last name, some JavaScript code checks to see whether there's already a Contact with that name. I'd like this code to fire when the user changes the Contact's name, and not wait until the user clicks Save.

 

I've read this, so I know how to create an S-control that includes HTML input tags for the Contact's first and last names, and I know how to add the onChange event handler for them. What I don't know is how to get the values of those fields saved as the Contact's first and last names when the user clicks Save.

 

If this can't be done in the standard page, I can write a VisualForce page. But if I go that route, can I use the <apex:detail> tag or do I have re-create the standard page layout manually, using individual inputField tags?

 

Thanks!

 

aalbertaalbert

You could use an Apex trigger to perform that logic and if a contact already exists, use the addError method in Apex to display the error in the UI. Deploying a trigger on the Contact which fires "after insert" and "after update" will add the equivalent to the event handler you are suggesting.

 

 

MJ09MJ09
Yup, but implementing this as a trigger requires the user to click Save before the Apex code runs. I was wondering if there's a way to run the code (perhaps via an S-Control) when the user changes the First or Last name fields, through an onChange (or perhaps onBlur) event.
vishantshvishantsh

Hello MJ Kahn,

 

I want to update one standard field drop down value from another standard field drop down value on change using AJAX.

I have seen your post that eloborates the similar problem. Did you find the answer anywhere..??

jp.narayan CVMjp.narayan CVM

This can be done using a homepage component.

 

Create a home page component as an HTML area, and within this write Javascript code for adding onchange event for your component. Inorder to do this the first step is to recognise your page which can be done using the Page Heading within the body, usually Edit screens will have name as Object Edit and New screens will have name as Object New. Once you recognise the page add Java script code for adding onchange event.

 

The only flaw with this approach is the home page component is rendered on each and every standard page, hence page recognision logic should be very nicely written

 

For more details contact me at jp.narayan@gmail.com. I have done it a number of times till date.

 

Thanks,

JP

 

 

MJ09MJ09

Good creative thinking, but the other flaw is that if the sidebar is collapsed, the sidebar's components aren't rendered, so the JavaScript doesn't run. Nice try, though....  :)

 

SalesforceEnthusiastSalesforceEnthusiast

Hi,

 

My requirement is: As we change/update any existing record in salesforce, I want to display a pop up box which lists the changes just made to the current record. Further user can confirm the changes by clicking "OK" or "Cancel" the change to return to the edit record page.

 

I have tried to research, but at no avail.

I am new to Salesforce, any help is highly appreciated.

 

Thanks