On a mileage form we have created, if we save it as a draft and then go back into to add additional auto-calculated rows (database lookup), each added row automatically adds the value 4.5 (sometimes a different value) in the miles field.
I have not been able to figure out why it is doing this and was wondering if anyone would be able to help try to solve the mystery. Below is a screenshot of part of the form and also the custom JavaScript we are using on the form.
In the above picture I simply loaded a saved draft and then clicked on "Click to add miles" link and it automatically put in the miles values even though the To and From options were not selected.
$(document).ready(function () {
//make fields with read-only class read-only
$('.read-only input').attr('readonly',true);
$('.read-only select').attr('disabled',true);
//Start Add row mile fields together
$('.cf-table-block').change(sumtotal);
function sumtotal() {
var sum = 0;
$('td.sum').each(function () {
var s = 0;
$(this).find('input').each(function () {
if ($(this).closest('td').siblings('td.roundTripCheck').find('input').is(':checked')) {
s += parseNumber($(this).val() * 2)
}
else {
s += parseNumber($(this).val());
}
})
$(this).find('.subtotal input').val(s);
sum += s;
});
$('.total input').val((sum).toFixed(2));
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
//End Add row mile fields together
//Start Calculate mileage reimbursement
$('.cf-table-block').on('change', 'input', sumreimbursement);
function sumreimbursement() {
var s = 0.44;
$('.totalmiles input').each(function () {
s *= parseNumber($(this).val());
});
$('.totalreimbursement input').val((s).toFixed(2));
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
//End Calculate mileage reimbursement
//Uncheck verify checkbox field
document.getElementById('Field51-0').checked = false;
//End Uncheck verify checkbox field
//Start Auto Fill
function tableAutofill() {
$('.cf-table-block tbody tr').each(function () {
$(this).find('button.autofill').trigger('click');
});
}
function autofill() {
//$('.autofill').trigger('click');
$(this).closest("tr").find('button.autofill').trigger('click');
}
$('.lookupCondition input').blur(autofill);
$('.lookupCondition select').blur(autofill);
$('.cf-table-add-row').click(function(){
$('.lookupCondition input').blur(autofill);
$('.lookupCondition select').blur(autofill);
});
//$('.cf-table-block').change(tableAutofill);
//End Auto Fill
});
Thanks in advance for your help.