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
KevinSnellKevinSnell 

jQuery Row Totals - Help with Row Id's

Hey all,

Hoping someone can help me with this simple issue.

I have the following jQuery which calculates the total for each row as the user inputs the data.  I need to show the total to the user before they committ the data to the database.  

<script>
       var j$ = jQuery.noConflict();

       j$(document).ready(function(){
           
           j$("[id$='qty'], [id$='cst']").blur(function(){
               var unitCost = j$("[id$='cst']").val();
               var quantity = j$("[id$='qty']").val();
               var totCost = +unitCost + +quantity;
               j$("[id$='tol']").val(totCost);
           });
       });
  </script>

Unfortunatlely it only works on the first row.  As far as I can tell the issue is around the jQuery not handling the row id's correct so it doesn't understand what it should be calculating.  For example the first row has the id: j_id0:j_id5:j_id6:wtable:0:cst and the next row id is: j_id0:j_id5:j_id6:wtable:1:cst.  So the number is increasing each time a row is being added.

So I need some help to add the number to the variables in the jQuery.

If anyone can help it would be really appreciated.

Thanks

Kev

Edwin VijayEdwin Vijay
I am not sure about jQuery. But, i guess you could do the same with standard visualforce tags using rerender and actionsupport?