I’ve just loaded up your page code in my text editor, and there is something first that can do with being fixed.
Line 638 has a missing double quote symbol, which should read:
<div id="collapsefive" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFive">
Aside from that though, you will be able to use less once your field names are consistent with each other. For example, the following type of code would be close to perfect:
$('#checkboxes-0:checked').on('click', function () {
if ($(this).is(':checked')) {
copyFields('#collapsefive :input', 'C', 'ROA');
}
});
The only thing getting in the way is that some of your identifiers are inconsistent.
- ROAcountry
- Caddcountry
- PPBcountry
- BOAcountry
The Caddcountry name will not be able to work with the others, until it’s renamed to Ccountry instead, and likewise for other fields in that same area.
Once things are consistent for the C group, you’ll be able to use smaller code to let you copy the fields:
You can replace the code from post #8 with the following, to see what I mean:
function copyFields(parentSelector, targetPrefix, sourcePrefix) {
var missing = [];
$(parentSelector).each(function (index, field) {
if (field.type === 'checkbox') {
// avoid the "same as" checkboxes.
// A better technique will be wanted if checkboxes are to be copied too
return;
}
var sourceId = sourcePrefix + field.id.substring(targetPrefix.length),
sourceField = $('#' + sourceId);
if (sourceField.length === 0) {
missing.push(field.id);
return;
}
if (field.tagName === 'SELECT') {
field.options.selectedIndex = sourceField.options.selectedIndex;
} else {
$(field).val(sourceField.val());
}
});
if (missing.length > 0) {
alert('Cannot find matching fields for: ' + missing);
}
}
$('#checkboxes-0:checked').on('click', function () {
if ($(this).is(':checked')) {
copyFields('#collapsefive :input', 'C', 'ROA');
}
});
I’ve also added an alert for missing matching fields, to help you diagnose any that don’t match too.