Contructing a well formatted address from address components (using Script)

The following script will build a well formatted address from standard address components:

function clientAddr() {

var address = '';

if (fld('Client_Addr_CO_txt').val() !== '') {
address = address + fld('Client_Addr_CO_txt').val() + ' ';
}

if (fld('Client_Addr_Level_txt').val() !== '') {
address = address + fld('Client_Addr_Level_txt').val() + ' ';
}

if (fld('Client_Addr_1_txt').val() !== '') {
address = address + fld('Client_Addr_1_txt').val() + ', ';
}

if (fld('Client_Addr_2_txt').val() !== '') {
address = address + fld('Client_Addr_2_txt').val() + ', ';
}

if (fld('Client_Addr_Suburb_txt').val() !== '') {
address = address + fld('Client_Addr_Suburb_txt').val();
}

if (fld('Client_Addr_State_txt').val() !== '') {
address = address + ' ' + fld('Client_Addr_State_txt').val();
}

if (fld('Client_Addr_PC_txt').val() !== '') {
address = address + ' ' +fld('Client_Addr_PC_txt').val();
}

if (fld('Client_Addr_Country_cho').val() !== 'Australia') {
address = address + ' ' + fld('Client_Addr_Country_cho').val();
}

fld('Client_Addr_scr').val(address);

}