• Dinesh Bharadwaj
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hi

 

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>
           
            <apex:column headervalue="Sales Price" id="prodSalesPriceCol" >
             <apex:outputtext  id="prodSalesPrice" value="{!salesPriceCalc}"/>
                       </apex:column>

 

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;
        salesPriceUpdate(sellingPrice);
       }

 

Any help is greatly appreciated.

  • April 25, 2013
  • Like
  • 0

Okay,

 

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;
	}
</script>
	<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>
		</apex:pageblock>		
	</apex:form>
</apex:page>

 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