You need to sign in to do that
Don't have an account?
laks
Updating a field dynamically in pageBlockTable
Hi,
My requirement is that I want a field(column) in pageBlockTable to be calculated dynamically based on 2 other fields.
I have 3 columns - Order quantity, Unit Price & Total Extended Price.
What I want to do is :
Whenever the value under Order quantity is changed in a row, the corresponding Total Extended Price should be calculated and refreshed (Total Extended Price = Order quantity * Unit Price ).
How can I achieve the same in Visualforce ?
Thanks in advance.
Regards,
Lakshmi.
Hi ,
You can add the above functionality by using javascript which will update the total price onblur of the textbox you are changing.
Sample code :
Hope this sample code will help you out with your requirement.
Please mark as solution if you get help with this.
All Answers
I got it to work by using actionSupport, param tags and controller action method to perform the calculation.
The problem I am facing now is that the value before change is taken from my inputtext field for the calculation, whereas I want the value that I have entered now.
VF page code:
Controller code:
Can anybody tell me what I am doing wrong here.
Regards,
Lakshmi.
Hi ,
You can add the above functionality by using javascript which will update the total price onblur of the textbox you are changing.
Sample code :
Hope this sample code will help you out with your requirement.
Please mark as solution if you get help with this.
That worked fine Vikash :-)
Thanks a lot .
Regards,
Lakshmi.
It
It is giving me sysntax error . Can I know why ?
<apex:page standardController="Account" recordSetVar="accs" sidebar="false">
<script type="text/javascript">
function computeTotal(quantityId, unitPriceId, totalId){
var quantity = document.getElementById(quantityId).value;
var cost = document.getElementById(unitPriceId).innerHTML;
var totalPrice = quantity * cost;
document.getElementById(totalId).innerHTML = totalPrice;
}
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!accs}" var="acc">
<apex:column headerValue="Quantity">
<apex:inputText id="quantity" onblur="computeTotal('{!$Component.quantity}','{!$Component.unitPrice}','{!$Component.total}');"/>
</apex:column>
<apex:column headerValue="Unit Price">
<apex:outputText id="unitPrice" value="10"/>
</apex:column>
<apex:column headerValue="Total Price">
<apex:outputText id="total"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Please help me
I use the same code as above in best answer. But it is renedering as 'NaN'.
Does it occuring like this because my unit price field is of type currency ?
Please help !
Thanks in advance