Adding Javascript?

acoganacogan Community Member Qubie ✭

Adding Javascript?

Hello! I am new to computer programming and hoping to figure out how to add some Javascript to the survey I'm running for my lab.

I got the code from here: https://developers.google.com/recaptcha/docs/v3

grecaptcha.ready(function() { grecaptcha.execute('_reCAPTCHA_site_key_', {action: 'homepage'}).then(function(token) { ... }); });

When I try to save the pasted code into the "Add Javascript" box, I get an error message ("Unexpected token <"). Clearly I'm out of my depth, but my hope is that getting this code to work with our survey might be a fixable problem. I think this bot-detection functionality may be available on Qualtrics, but our school account doesn't seem to have access to this user-friendly version of the feature.

I would so appreciate any help or advice you can spare. Thank you for your time!

Tagged:

Best Answer

  • KoalaTricksKoalaTricks Boston Guru ✭✭
    Accepted Answer

    It sounds like you pasted all of the code from the first snippet at the URL, which is HTML (it has the <>) and not pure JavaScript.

    You would want to put the first line in the header of your survey (the source editor, not the WYSIWIG editor):

    <script src="https://www.google.com/recaptcha/api.js?render=_reCAPTCHA_site_key"></script>
    

    And then only this part on the question-level "Add Javascript" where you want it to appear. I am assuming you already have the requisite site key and token -- it won't work otherwise.

    grecaptcha.ready(function() {
        grecaptcha.execute('_reCAPTCHA_site_key_', {action: 'homepage'}).then(function(token) {
           ...
        });
    });
    

Answers

Sign In to Comment