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
dev_jhdev_jh 

VF Page: Field changing when a related field changes

Hi all,

 

Not sure if this is possible on Visualforce and how to do it.

 

I have an extension to a standard controller with some extra functions that will set a field (let´s call it A) to a calculated value depending on another field (let´s call that one B).

 

Now when B, which is a dropdown field, changes, I want A to be recalculated.

 

In other words, I want an Onchange event on field B (you can have these type of events) that calls a function within the Controller. The problem is that from an onchange event you can call Javascript, but I don´t know how to call an Apex function from within Javascript.

 

Can this be done? Thanks,

 

J

Best Answer chosen by Admin (Salesforce Developers) 
VisualForceVisualForce

Hi..

 

Use actionsupport tag with attributes rerender or action

 

<apex:selectlist value="{!B}" size="1" id="B"> <apex:selectoptions value="{!B_Items}"/> <apex:actionsupport event="onchange" rerender="A"/> </apex:selectlist> <apex:inputtext value={!A}" id="A"/>

 

All Answers

dev_jhdev_jh
I managed to get it working without the need of using Javascript...
VisualForceVisualForce

Hi..

 

Use actionsupport tag with attributes rerender or action

 

<apex:selectlist value="{!B}" size="1" id="B"> <apex:selectoptions value="{!B_Items}"/> <apex:actionsupport event="onchange" rerender="A"/> </apex:selectlist> <apex:inputtext value={!A}" id="A"/>

 

This was selected as the best answer