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
Zack ThomasZack Thomas 

Calculating field value inside a repeat tag

My problem is that I need to be able to calculate the multiplicative result of two fields inside the loop and then display that result in an outputText field.

The first thing I tried was to see if it was possible to multiply the two fields together inside the SOQL statement and have the result inside the result set, but SOQL doesn't seem to support that. The next thing I tried was to see if I could make a call back to the Apex code I'm using as an extension to multiply the fields as they're rendered, but there doesn't seem to be a way to make a function call such as that from visualforce. The next thought was to possibly use a javascript call to multiply and render client-side, but there doesn't seem to be any intuitive way to accomplish that either.

Am I on the wrong train of thought? Did I miss something? Or is there merely no feasible way at this point in time to accomplish anything such as this?

Thanks!
Ron HessRon Hess
i think you can use a formula field to multiply two fields, then you have that field in available to return in a soql statement.
hokusaihokusai
I have the same problem and I will use a formula field.  However moving forward is there a way to use javascript or a formula to set the value of an output text in a column in a data table? 

today I can do :
 <apex:outputText value="{!oli.Discounted_Price__c}"/>

Is there a way to use a subtract function on the page?
 <apex:outputText value="javascript:subtract({!oli.Total__c},{!oli.Discount__c})"/>

Am I missing some simple way to use javascript to control values?