Hi,
I have a policy application that has three different date fields and a number (Active #) field in a table. The date fields are "From" (start of policy), "To" (end of policy) and "Add/Delete" (date of any change made to the policy) dates. The number field by default calculates the difference between the "To" and "From" dates. The "Add/Delete" field initially defaults to the "To" date but is editable and as such when there is a change in the policy, this date is edited and as such the number field calculates the difference between the "From" and "Add/Delete".
To = Add/Del
Active # = Add/Del - From
I managed to do this with the below code.
//Date Calculation
$('.cf-table-block').on('change', 'input', sumtotal);
$('.dateClass').on('change', 'input', sumtotal);
function sumtotal() {
$('.cf-table-block tbody tr').each(function () {
var t1 = 0;
var t2 = 0;
var diff = 0;
var expiry = 0;
t1 = new Date($(this).find('.startDate input').val());
//Copying Date
$('.endDate input').change(function () {
expiry = new Date($(this).val().toString());
$('.addDelClass input').val(expiry);
});
t2 = new Date($('.addDelClass input').val());
day1 = (Math.floor((t2-t1)/(1000*60*60*24))) + 1;
$(this).find('.dateDiff input').val(diff);
});
}
The challenge am getting is that when I add another row, the "Add/Delete" date on all the rows change to the value of "To" date of the second row when only the one on the second row should be affected. What am I not doing right to ensure that the "To" value affects only the :Add/Del" value on it's row.
Secondly I would appreciate advise on how, when I add the second row, these fields are copied onto the second row then I just change where necessary.