Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Visualforce Development
- :
- simple calculation within page
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
simple calculatio n within page
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-05-2012 02:23 PM
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>
Solved! Go to Solution.
Re: simple calculatio n within page
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-06-2012 03:42 AM
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
Re: simple calculatio n within page
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-06-2012 09:12 AM
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?
Re: simple calculatio n within page
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-09-2012 08:42 PM
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 ...
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.
Re: simple calculatio n within page
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-13-2012 08:24 AM
works. don't know why i didn't even try that. Thanks.

