I'm trying to populate an amount field at the top of a table when a row's checkbox is selected, this is only for UI purposes and does not need to be written to the DB.
The checkbox itself is a field on a record, so using $(this).val to get its value doesn't work. There is another field on the row, which is called Total_Including_GST__c, this is the field that i need to sum.
How would I write the JS to grab the fields value?
VF:
<input class="form-control" style="height:42px;" disabled="disabled" id="price" type="number" name="amount" placeholder="Selected Amount"/>
<table id="invoicesTable" class="table table-striped" style="width:100%;">
<thead class="tableHeadBlue">
<tr>
<td>Invoice Number</td>
<td>Invoice Date</td>
<td>Invoice Amount</td>
<td>Remittance Amount</td>
<td>Remittance #</td>
<td>Balance</td>
<td style="text-align: center;">Reconciles? <apex:inputCheckbox style="font-size:30px;" styleClass="check" onclick="selectAllCheckboxes(this,'inputId1')"/></td>
<td align="right" style="width:120px;">Action</td>
</tr>
</thead>
<tbody>
<apex:repeat value="{!getInvoicesOut}" var="invOut">
<tr>
<td><apex:outputField styleClass="form-control" value="{!invOut.OrderNumber}"/></td>
<td><apex:outputField styleClass="form-control" value="{!invOut.EffectiveDate}"/></td>
<td><apex:outputField id="totalAmount" styleClass="form-control total" value="{!invOut.Total_Including_GST__c}"/></td>
<td><apex:inputField styleClass="form-control" value="{!invOut.Payment_Received__c}" html-placeholder="$0.00"/></td>
<td><apex:inputField styleClass="form-control" value="{!invOut.Payment_Received_Number__c}" html-Placeholder="Remittance #"/></td>
<td><apex:outputField styleClass="form-control" value="{!invOut.Balance_Calculated__c}"/></td>
<td>
<label class="formCheck">
<apex:inputCheckbox id="inputId1" styleClass="check" style="font-size:24px;" onchange="selectedCheckbox();" value="{!invOut.Remittance_Reconciles__c}"/>
<!--<input type="checkbox" id="inputId2" class="check" style="font-size:24px;" value="{!invOut.Total_Including_GST__c}"/>-->
</label>
</td>
<td><apex:outputlink style="text-decoration:none;" styleClass="pull-right" target="__blank" value="/{!invOut.id}">View Invoice</apex:outputlink></td>
</tr>
</apex:repeat>
</tbody>
</table>
JS:
$('input[class="check"]').change(function(){
var totalprice = 0;
$('input[class="check"]:checked').each(function(){
totalprice = totalprice + parseInt($(this).val());
});
$('#price').val(totalprice);
});
Best Answer
Since the field is read-only, I'd suggest you just move the data to the checkbox itself:
Which you can get in your method:
Self-Contained Example
Controller
Page