Find your content:

Search form

You are here

How to add the the values in a particluar column under pageblocktable using Javascript?


I have a pageblock table to display the list of accounts and i have few buttons on my VF page like add row,delete etc.User can change the values in the columns and update the records. I want to add the values in a particular column(Quantity) and give an alert to user like ' sum of all the values after change ...' on clicking the buttons.

Attribution to: Keepcalmncode

Possible Suggestion/Solution #1

function texttoNo(){

 var Entirepageblock       =document.getElementById('{!$}');

var inputElem = Entirepageblock.getElementsByTagName("input");

for(var i=0; i<inputElem.length; i++) {


alert('Please enter only integer quantities.');

 inputElem[i].value = 0;





I have used this Javascript to get the values from each of the column dynamically .May be you may like to tweak this and sum all the columns and onclick of button validate

Attribution to: Mohith Shrivastava

Possible Suggestion/Solution #2

Assuming you are sending the users updates back to the controller, you could simply sum the values there and store in a property. You could then set another property to indicate the alert should be shown. That way you are decoupled from how you are rendering the data. It would be something like the following in the controller:

public Boolean showAlert {get; set;}
public double total {get; set;}

public PageReference update()
    // calc total

and on the page:

<apex:outputPanel rendered="{!showAlert}">
       alert('The new total is {!total}');

this is pretty simplistic, you'd also need to make sure to clear the showAlert flag when the page was submitted back in a way that didn't involve an update.

Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content