You need to sign in to do that
Don't have an account?
edawson
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>
Try this:
Anything that you can do in a formula, you can do in a merge field ...
All Answers
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
I don't think that is the problem.
This tag renders the PurchPrice__c as expected with currency formatting:
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?
Try this:
Anything that you can do in a formula, you can do in a merge field ...
works. don't know why i didn't even try that. Thanks.