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
Anna Lu 6Anna Lu 6 

using javascript within <script> tag

I want to insert a value generated from javascript to visualforce page, but it does not work. Here's my sample code (my real task is to do some calculation in <script>, so I simply cannot tape in apex tag directly):
<apex:page controller="CAReportAvgFine" >
    
 <apex:sectionheader title="Compliance Advisory Report" subtitle="Saved Penalty"/>
 
 <apex:outputText id="fine"> 76534</apex:outputText>
  <script>
        
        document.getElementByID("{!$Component.fine}").innerHTML= "8965478" ;
  </script>

<style></style>
</apex:page>

Could anyone help?

I know a lot answers are using javascript as a static file... but I still want to use it here within this page. 

Thank you! 
 
Aman MalikAman Malik
Hi,
Try Below snippet:
<apex:page  controller="CAReportAvgFine" >
    
 <apex:sectionheader title="Compliance Advisory Report" subtitle="Saved Penalty"/>
 
 <apex:outputText value="76534" id="fine"></apex:outputText>
  <script>
        
        document.getElementById("{!$Component.fine}").innerHTML= "8965478" ;
  </script>

<style></style>
</apex:page>
Its working, I have verified.

Please like the answer and mark it best if this helps.

Thanks,
Aman
 
Aman MalikAman Malik
In your previous code, there were two problems:
1) you wrote 'getElementByID' instead of 'getElementById'.
2) you did not pass value in value attribute.
Aman MalikAman Malik
Hi Anna,

Just taking a follow-up. Is your issue resolved.
If yes, Please like the answer and mark it as best.

Thanks,
Aman
Afzaal HassanAfzaal Hassan
What would you need to do, if you want to render this barcode as a pdf? It works fine in html, but  when I put the renderAs tag as pdf, the barcode doesnt show up