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
Amit_Amit_ 

How to use actionsupport to set value.

Hi All,

First of all thanks for looking my post. I am facing a small problem, if you can look at my code nad help me out then it will be great help. the problem is I have quantity, unitPrice and Amout fileds in VF page. Quantity and amount is a entity of Wrapper class and unitPrice is a entity of pricebooktable. Now my requirement is onChange of qunity the amout should automatically be calculated as Quantity * UnitPrice, here what I am trying to do : 

<apex:pageBlockTable value="{!lsPwr}" var="tmpVar">
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!tmpVar.isSelected}"/>
</apex:column>
<apex:column value="{!tmpVar.prodObj.name}" headerValue="Product Name"/>
<apex:column value="{!tmpVar.prodObj.ProductCode}" headerValue="Product code"/>
<apex:column value="{!tmpVar.prodObj.Category__c}" headerValue="Product Category"/>
<apex:column id="productUnitPrice" value="{!tmpVar.pricebookObj.UnitPrice}" headerValue="Product Price Per Unit"/>
<apex:column headerValue="Quantity">
<apex:inputtext value="{!tmpVar.quantity }">
<apex:actionSupport event="onchange" reRender="quantity" />
</apex:inputText>
</apex:column>
<apex:column id="quantity" value="{!tmpVar.pricebookObj.UnitPrice}*{!tmpVar.quantity }" headerValue="Amount"/>
</apex:pageBlockTable>

 

lsPwr is a list of wrapper class. I dont know how to display amount as(unitPrice * quantity) I am using apex:actionSupport event =onChange on inputtext quantity.

 

please suggest me to solve the problem.

 

 

Thanks & Regards,

Amit_

Avidev9Avidev9

I guess you can give  a try to this

 

<apex:pageBlockTable value="{!lsPwr}" var="tmpVar" id="myPBT">
    <apex:column headerValue="Select">
        <apex:inputCheckbox value="{!tmpVar.isSelected}" />
    </apex:column>
    <apex:column value="{!tmpVar.prodObj.name}" headerValue="Product Name" />
    <apex:column value="{!tmpVar.prodObj.ProductCode}" headerValue="Product code" />
    <apex:column value="{!tmpVar.prodObj.Category__c}" headerValue="Product Category" />
    <apex:column id="productUnitPrice" value="{!tmpVar.pricebookObj.UnitPrice}" headerValue="Product Price Per Unit" />
    <apex:column headerValue="Quantity">
        <apex:inputtext value="{!tmpVar.quantity }">
             <apex:actionSupport event="onchange" reRender="myPBT" />
        </apex:inputText>
    </apex:column>
    <apex:column id="quantity" value="{!tmpVar.pricebookObj.UnitPrice*tmpVar.quantity }" headerValue="Amount" />
</apex:pageBlockTable>

 

Here in this code, the pageblock table is rerendered to reflect the changes

Amit_Amit_

Hi Avi,

 

I am using your code but the output i'm getting in amount filed on VF page as 2000* 2 where 2000 is unitPrice and 2 is Quantity which Iam giving it is not calculatting and giving the result as 4000. 

can you suggest me why its not giving the result  or there is me some other way to get a desired result

Avidev9Avidev9
just edited the answer there was an mistake. Please use the edited code