+ Start a Discussion

How does one call a javascript in VF???

I have the following:


<apex:page standardController="SFDC_520_Quote__c" extensions="salesQuotes" showHeader="false" sidebar="false" tabStyle="SFDC_520_Quote__c" renderAs="PDF"> <script> function formatCurrency(num) { num = num.toString().replace(/ \|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + '' + num + '.' + cents); } </script> <style> h2 {color: #dddddd; font-size: 24px; } .teststyle {color: #ff3300;} </style> <apex:pageBlock> <apex:stylesheet value="{!URLFOR($Resource.pdfresource, 'styles.css')}"/>

 I need to call it here: How do I call it around UnitPrice???


<apex:pageBlockTable value="{!SFDC_520_Quote__c.quote_lines__r}" var="item" border="1" cellspacing="0" cellpadding="0" style="font-size:10px; font-family:courier;"> <apex:column headerValue="Unit Price"> <apex:outputText value="{!item.Unit_Price__c}"/> </apex:column> </apex:column> </apex:pageBlockTable>






Ron HessRon Hess

something like this should work



<apex:column headerValue="Unit Price"> <script>formatCurrency('{!item.Unit_Price__c}');<script>





Ron's answer is right, but here are several comments.


You cannot depend on JavaScript in a page that renders as a PDF.


If Unit_Price__c is a currency field, you don't need the JavaScript function, just change apex:outputText to apex:outputField.


If apex:outputField is not formatted the way you want, and you really want to drop the currency ISO for the field, see my reply to your other post on how to do it using EL.