ReCaptcha-validation client-side not working

Hey, I have the same problem as the guy in this post: ReCaptcha not validated client-side or how to deal with form errors

I am using Google ReCaptcha in my modular form template.
The validation of the ReCaptcha is perfectly working on server-side, but I can’t get it run on client-side. So the user won’t get any failure message before submitting the form.

It would be much nicer, if the user would get a message before sending the form, in which he is asked to fill out the recaptcha.

Thank you!

I found a solution. Not the cleanest but it works (the ID of my form is “contact-form”):

    var form = document.getElementById('contact-form');
    form.addEventListener("submit", function(event){
            if (grecaptcha.getResponse() === '') {
                alert('Bitte füllen Sie das ReCaptcha aus.');
        , false);