I have an scenario where pageblocks in visualforce are dynamically rendered based on the list size. In each page block i am performing some calculations OnKeyup using javascript and JQ and result is stored in one field.My code works fine for single block.But its not working as expected for dynamically generated pageblocks.
<apex:page standardController="Calender_Year_Revenue__c" Extensions="calendaryear">
<apex:includeScript value="{!$Resource.jqueryCollapse}"/>
<apex:includeScript value="{!$Resource.jqueryCollapse1}"/>
<apex:includeScript value="{!$Resource.jqueryCollapse2}"/>
<apex:includeScript value="{!$Resource.jquerycollapse21}"/>
<apex:form >
<apex:pageBlock >
<Apex:PageBlockSection columns="2" >
<apex:repeat value="{!lc}" var="c" id="repeat">
<apex:inputField label="{!c.Label__c}" value="{!cy.Revenue__c }" onchange="calculate(this);" styleClass="Rptcls" >
</apex:inputField>
</apex:repeat>
<apex:inputField label="Terms" value="{!cy.Terms__c }" styleClass="Rptcls" />
<apex:inputField id="Rep" label="Total" value="{!cy.TotalRevenue__c }" styleClass="Rptcls1" />
<apex:commandButton value="Submit" action="{!action}"/>
<apex:param name="action" value="{!cy.Revenue__c}"/>
</Apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script>
$(document).ready(function() {
$(".Rptcls").on('keyup',function(){
var sum= 0;
$(".Rptcls").each(function() {
if(!isNaN($(this).val()) && $(this).val().length!=0) {
sum += parseFloat($(this).val());
$(".Rptcls1").val(sum);
}
});
});
});
</script>
</apex:page>
var="c"because it has been used ascas well ascy. Also have you a JS function calledcalculate()? any script errors?