jQuery(function($) { function updateReturnAddressName() { const input = $('#config_return_address_name'); if (!input.val().length) { let name = $('#config_name').val() + ' ' + $('#config_surname').val(); if ($('#config_is_company').prop('checked')) { name = $('#config_company').val() + ' - ' + name; } input.val(name); } } function enableDisableFieldset() { const checkbox = $(this); checkbox.closest('fieldset').find('input,select').prop('disabled', !checkbox.prop('checked')); checkbox.prop('disabled', false); } $('#config_return_address_enabled').change(enableDisableFieldset).change(); $('#') $('#config_company, #config_is_company, #config_name, #config_surname').change(updateReturnAddressName); $('config_house').change(function() { const input = $('#config_return_address_house'); if (!input.val().length) { input.val($(this).val()); } }); $('config_flat').change(function() { const input = $('#config_return_address_flat'); if (!input.val().length) { input.val($(this).val()); } }); $('config_zip_code').change(function() { const input = $('#config_return_address_zip_code'); if (!input.val().length) { input.val($(this).val()); } }); $('config_town').change(function() { const input = $('#config_return_address_town'); if (!input.val().length) { input.val($(this).val()); } }); });