const addCallback = setTimeout(() => { // Need to check reCaptcha exists before adding callback // or reCaptcha will fail to load if ($('#IsRecaptchaEnabled').val() == 'true') { if (grecaptcha) { const rcv2 = document.querySelector('.g-recaptcha'); if (rcv2 != null) { rcv2.dataset.callback = "ShowErrorMessage"; } clearTimeout(addCallback); } } }, 5); function ShowErrorMessage() { const response = grecaptcha.getResponse() if (response.length !== 0) { $('#lblErrorMessage').attr("style", "display:none"); } } $(document).ready(function () { $('#lblErrorMessage').attr("style", "display:none"); if ($('#IsRecaptchaEnabled').val() != 'true') { $(".g-recaptcha").attr("style", "display:none"); } }); function ValidateCaptcha() { var response = ''; if ($('#IsRecaptchaEnabled').val() == 'true') { response = grecaptcha.getResponse(); } if (response.length == 0 && $('#IsRecaptchaEnabled').val() == 'true') { $('#lblErrorMessage').attr("style", "display:block"); $('#lblErrorMessage').text($('#ReCaptchaErrorMessage').val()); return false; } else { $(".g-recaptcha").attr("style", "display:none"); } }