Reply
Contributor
edawson
Posts: 3
0
Accepted Solution

simple calculation within page

I'd like to display a value calculated from custom fields in a visualforce page without resorting to writing a custom controller. I tried writing a javascript function with no luck. Any help would be greatly appreciated.

 

below is my code for the page. when I try to save i get the error, "Error: The value attribute on <apex:outputText> is not in a valid format. It must be a positive number, and of type Number, Date, Time, or Choice."

 

<apex:page standardController="Property__c">
<script type="text/javascript"> 
function totalCost() {
    var price = {!Property__c.PurchPrice__c};
    var rehab = {!Property__c.TotalRehab__c};
    var totCost = price + rehab;
    return totCost;
    }
</script>
  <apex:outputText value="Purchase: "/><apex:outputText value="{0, number, $###,###}"><apex:param value="{!Property__c.PurchPrice__c}" /></apex:outputText><br/>
  <apex:outputText value="Rehab: "/><apex:outputText value="{0, number, $###,###}"><apex:param value="{!Property__c.TotalRehab__c}" /></apex:outputText><br/>
  <apex:outputText value="Total: "/><apex:outputText value="{0, number, $###,###}"><apex:param value="totalCost()" /></apex:outputText><br/>
</apex:page>

 

Regular Contributor
RollNo1
Posts: 12
0

Re: simple calculation within page

The second outputtext tag you have used thats casuing the error... Instead of that try 

<apex:outputText value="Total: " style="{0, number, $###,###}"/>

 

You are trying to specify the style in value attri. thats not possible

Contributor
edawson
Posts: 3
0

Re: simple calculation within page

I don't think that is the problem.

 

This tag renders the PurchPrice__c as expected with currency formatting:

 

<apex:outputText value="{0, number, $###,###}"><apex:param value="{!Property__c.PurchPrice__c}" /></apex:outputText>

 

I think the problem is my apex markup is not recognizing the javascript function as returning a number value. Do you know if there is some syntax I am missing that would indicate to the apex tags that the value returned by that function in the javascript will be a number?

Trusted Contributor
SFF
Posts: 232
0

Re: simple calculation within page

Try this:

 

<apex:page standardController="Property__c">
  <apex:outputText value="Purchase: "/><apex:outputText value="{0, number, $###,###}"><apex:param value="{!Property__c.PurchPrice__c}" /></apex:outputText><br/>
  <apex:outputText value="Rehab: "/><apex:outputText value="{0, number, $###,###}"><apex:param value="{!Property__c.TotalRehab__c}" /></apex:outputText><br/>
  <apex:outputText value="Total: "/><apex:outputText value="{0, number, $###,###}"><apex:param value="{!Property__c.PurchPrice__c + Property__c.TotalRehab__c}" /></apex:outputText><br/>
</apex:page>

Anything that you can do in a formula, you can do in a merge field ...

 

John Westenhaver
Salesforce Fast

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Contributor
edawson
Posts: 3
0

Re: simple calculation within page

works. don't know why i didn't even try that. Thanks.