Thanks to Andar, my one line of code became many!
I still have one problem that I'm able to see.
$(document).ready(function(e){
if ($('#form_13339').length > 0 ){
$("#element_1_1").on('focus blur',function(e){
mergeTrustees();
});
$("#element_1_2").on('focus blur',function(e){
mergeTrustees();
});
$("#element_1_3").on('focus blur',function(e){
mergeTrustees();
});
$("#element_2_1").on('focus blur',function(e){
mergeTrustees();
});
$("#element_2_2").on('focus blur',function(e){
mergeTrustees();
});
$("#element_2_3").on('focus blur',function(e){
mergeTrustees();
});
}
});
function mergeTrustees() {
var iTFirst = $("#element_1_1").val();
var iTMiddle = $("#element_1_2").val();
var iTLast = $("#element_1_3").val();
var iTrustee = buildName(iTFirst, iTMiddle, iTLast);
var sTFirst = $("#element_2_1").val();
var sTMiddle = $("#element_2_2").val();
var sTLast = $("#element_2_3").val();
var sTrustee = buildName(sTFirst, sTMiddle, sTLast);
var trustees = $("#element_3").val();
if (sTrustee != '') {
trustees.val(iTrustee + ' and/or '+ sTrustee );
} else {
trustees.val(iTrustee);
}
};
function buildName(first, middle, last) {
if (middle != '') {
return first + ' ' + middle + ' ' + last; // code block
} else if (first != '' && last != '') {
return first + ' ' + last;
} else {
return '';
}
};
I get the following error in the debug console when I try to write the concatenated value to the field trustees:
custom_13339.js:50 Uncaught TypeError: trustees.val is not a function
at mergeTrustees (custom_13339.js:50:18)
at HTMLInputElement.<anonymous> (custom_13339.js:6:12)
at HTMLInputElement.dispatch (jquery.min.js?9f6d23:2:43064)
at v.handle (jquery.min.js?9f6d23:2:41048)
Can someone help me please?