• Dinesh Bharadwaj
  • 0 Points
  • Member since 2015

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2



I have a pageblock table which displays a list of product records. The list of products shows product name,family,description ,quantity,discount,standard price and salesprice.


When the user enters discount value in the input text onchange triggers a call to javascript where salesprice is calculated : standardprice- (standardprice*discount)/100;


Iam able to read the values in the javascript and calculate salesprice. I am unable to set the salesprice to the outputText column in the table .


Here is  my vf page  partial markup:

<apex:actionFunction name="salesPriceUpdate" 
                     action="{!fieldUpdate}" rerender="prodSalesPrice,prodSalesPriceCol" /> 


<apex:column headervalue="Discount %"  >
               <apex:inputtext value="{!products1.discount}" id="discPcrnt" onchange="CalculateSP('{!$Component.discPcrnt}','{!$Component.stdPrice}'),'{!$Component.prodSalesPrice}';" />
            <apex:column headervalue="Sales Price" id="prodSalesPriceCol" >
             <apex:outputtext  id="prodSalesPrice" value="{!salesPriceCalc}"/>


Here is the javascript function:


<script language="javascript">
           function CalculateSP(disc,stndPrice,salesPrice){
              var discPcrnt=document.getElementById(disc).value;
               var stdPrice= document.getElementById(stndPrice).innerHTML;
               var discPrice= stdPrice*discPcrnt/100 ;
       var sellingPrice= stdPrice - discPrice ;
              document.getElementById(salesPrice).innerHTML = sellingPrice;
        document.getElementById(prodSalesPrice).innerHTML = sellingPrice;


Any help is greatly appreciated.

  • April 25, 2013
  • Like
  • 0



I'm feeling incredibly stupid here. I've been using a Apex Class to handle a lot of the calculations for a page. This works and it also incredibly slow. There are multiple inputs with each one requiring a series of calculations and partial page re-renders. This causes a lot of slow down with all the client -> server communication.


So, I'm switching to Javascript. I've had some success with all the references and websites out there. I've successfully updated all the calculations that are done on InputText and InputField components. My issue is that this doesn't seem to work on OutputText and Outputfields.


Here's a quick example. It's more complex than this but really simply I'm having a javascript function populate InputFields, OutputFields and OutputText after the function is called.


<apex:page id="thepage">
<script type="text/javascript">
	function jsUpdateFields(){
		var vnum = 10;
		var vdollar = 5;
		var vtext = 'hello';
		document.getElementByID('{!Component.thepage.theform.thepageblock.InputField}').value = vnum;
		document.getElementByID('{!Component.thepage.theform.thepageblock.OutputField}').value = vdollar;
		document.getElementByID('{!Component.thepage.theform.thepageblock.OutputText}').value = vtext;
		return false;
	<apex:form id="theform">
		<apex:pageblock id="thepageblock"
			<apex:inputfield value="{!Myobject.MyNumber__c}" id="InputField" />
			<apex:outputfield value="{!MyObject.MyCurrency__c}" id="OutputField" />
			<apex:outputtext value="{!MyObject.CustomText__c}" id="OutputText" />
		<a href="#" onclick="jsUpdateFields()">Run Javascript</a>

 What happens: The inputfields update perfectly. The outputField and OutputText have no updates. If I change those components to inputs they work fine.

Here's the thing I don't want to have those to be inputs.


I've also tried using an apex function that calls the javascript function and then rerenders an outputpanel where my output fields are located. This also doesn't seem to work.

help! and thank you