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
kaulsaksoftkaulsaksoft 

Can i update the contents of a textbox in Visual Force page dynamically

Hi All

 

I have a problem like

 

There are four textboxes in a VisualForce Page and i want to show the sum of contents these textboxes in a summary textbox on an onchange event of the four textboxes. Can i do so.

 

Please Help needed.

 

kaulSaksoft

Edwin VijayEdwin Vijay

Sure you can do this...

 

You need to have a "actionsupport" tag.. "rerender" the "summary" text box on the onchange event..

 

Also have an action method to perform your calculations..

 

Let me know if you need any sample..

 

 

kaulsaksoftkaulsaksoft

thanx Edwin1 for ur reply. It would be really great if you provide me some sample.

 

I am trying to use the actionsupport but still find it a little difficult 

Edwin VijayEdwin Vijay

Here you go..

 

 

<apex:inputtext value="{!textbox1}">
<apex:actionsupport event="onchange" action="{!calculate}" rerender="summation" />

</apex:inputtext>

<apex:outputpanel id="summation">
<apex:inputtext value="{!total}"/>
</apex:outputpanel>

 

 Pls note that "Calculate" function will sum up the values in the textboxes in your Apex code...

 

"total" function will display this calculated value...

 

Hope this helps..

 

kaulsaksoftkaulsaksoft

Hi

 

I did the same thing in my ExtensionController. But the calculated value is not being displayed on the VisualForce Page

 

 

<apex:outputPanel id="vehicleLoan"> <apex:pageBlockSection title="Vehicle Loan" columns="2" rendered="{!CustomerFinancialDetail__c.Vehicle_Loan__c == true}"> <apex:pageblockSectionItem > <apex:outputLabel value="Vehicle loan monthly EMI"/> <apex:inputtext value="{!CustomerFinancialDetail__c.Vehicle_loan_monthly_EMI__c}"> <apex:actionsupport event="onchange" action="{!calculate}" rerender="summation" /> </apex:inputtext> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Total No of Years Of Loan" /> <apex:inputfield value="{!CustomerFinancialDetail__c.Total_no_of_years_of_loan_for_Vehicle__c}"/> </apex:pageblockSectionItem> <apex:outputpanel id="summation"> <apex:pageblocksection title="Total Current Value of All Liabilities"> <apex:pageblockSectionItem > <apex:outputLabel value="Total Current Value of All Liabilities"/> <apex:outputText value="{!CustomerFinancialDetail__c.Total_Current_Value_of_all_liabilities__c}"/> </apex:pageblockSectionItem> </apex:pageblocksection> </apex:outputpanel>

 

public class CustomerFin { private CustomerFinancialDetail__c Cfc; public Double total; public CustomerFin(ApexPages.StandardController controller) { this.Cfc= (CustomerFinancialDetail__c)controller.getRecord(); } public Double getTotal() { system.debug('AAAAAAA'); return total; } public void calculate() { total= Cfc.Vehicle_loan_monthly_EMI__c +10.0; system.debug('CCCCCC '+ Cfc.Vehicle_loan_monthly_EMI__c); system.debug('22222222 '+ total ); } }

the "total" value is not displayed in the VisualForce Page. Can this be because of the Extension controller

HeenaHeena

Hi,

 

Seems like u are not updating the correct variable. Also, the action method is having return type void, changing that to PageReference will help. Try this code: -

 

 

<apex:outputPanel id="vehicleLoan"> <apex:pageBlockSection title="Vehicle Loan" columns="2" rendered="{!CustomerFinancialDetail__c.Vehicle_Loan__c == true}"> <apex:pageblockSectionItem > <apex:outputLabel value="Vehicle loan monthly EMI field 1"/> <apex:inputtext value="{!CustomerFinancialDetail__c.Vehicle_loan_monthly_EMI1__c}"> <apex:actionsupport event="onchange" action="{!calculate}" rerender="summation" /> </apex:inputtext> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Vehicle loan monthly EMI field 2"/> <apex:inputtext value="{!CustomerFinancialDetail__c.Vehicle_loan_monthly_EMI2__c}"> <apex:actionsupport event="onchange" action="{!calculate}" rerender="summation" /> </apex:inputtext> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Vehicle loan monthly EMI field 3"/> <apex:inputtext value="{!CustomerFinancialDetail__c.Vehicle_loan_monthly_EMI3__c}"> <apex:actionsupport event="onchange" action="{!calculate}" rerender="summation" /> </apex:inputtext> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Vehicle loan monthly EMI field 4"/> <apex:inputtext value="{!CustomerFinancialDetail__c.Vehicle_loan_monthly_EMI4__c}"> <apex:actionsupport event="onchange" action="{!calculate}" rerender="summation" /> </apex:inputtext> </apex:pageblockSectionItem> </apex:pageblocksection> </apex:outputpanel> <apex:outputpanel id="summation"> <apex:pageblocksection title="Total Current Value of All Liabilities"> <apex:pageblockSectionItem > <apex:outputLabel value="Total Current Value of All Liabilities"/> <apex:outputText value="{!CustomerFinancialDetail__c.Total_Current_Value_of_all_liabilities__c}"/> </apex:pageblockSectionItem> </apex:pageblocksection> </apex:outputpanel>

 

public class CustomerFin { private CustomerFinancialDetail__c Cfc; public CustomerFin(ApexPages.StandardController controller) { this.Cfc= (CustomerFinancialDetail__c)controller.getRecord(); } public pageReference calculate() { CustomerFinancialDetail__c.Total_Current_Value_of_all_liabilities__c = Cfc.Vehicle_loan_monthly_EMI1__c + Cfc.Vehicle_loan_monthly_EMI2__c+ Cfc.Vehicle_loan_monthly_EMI3__c+ Cfc.Vehicle_loan_monthly_EMI4__c; return null; } }

 

 

 Hope it helps.

 

Thanks,

Heena

 

 

 

kaulsaksoftkaulsaksoft

Hi

 

I tried doing the same but still I am not getting any values. It si still display a null value.

Edwin VijayEdwin Vijay

Hi...

 

As Heena had said.. it seems you are not displaying the calculated value..

 

Below is the change you have to make in your VF page..

 

 

<apex:outputpanel id="summation"> <apex:pageblocksection title="Total Current Value of All Liabilities"> <apex:pageblockSectionItem > <apex:outputLabel value="Total Current Value of All Liabilities"/> <apex:outputText value="{!total"/> </apex:pageblockSectionItem> </apex:pageblocksection> </apex:outputpanel>

 

 Since total is the variable which has the calculated value.. ideally total should be displayed in your page..

I could see in your original code that you are displaying a field value, hence this would not display the calculated value..

 

Hope this helps..