const labels = document.querySelectorAll('#identityType label.form-check-label'); labels.forEach(label => { label.addEventListener('click', function() { const buttonName = label.textContent.trim(); changeButtons(buttonName); }); }); function changeButtons(buttonName) { var radioButtonYes = document.querySelector('input[name="identityType"][value="identityNumber"]'); var radioButtonNo = document.querySelector('input[name="identityType"][value="passportNumber"]'); if (buttonName === 'Yes') { radioButtonYes.checked = true; radioButtonNo.checked = false; radioButtonYes.dispatchEvent(new Event('change'));} else { radioButtonYes.checked = false; radioButtonNo.checked = true; radioButtonNo.dispatchEvent(new Event('change')); }}