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
<script src="https://www.google.com/recaptcha/api.js?render=_reCAPTCHA_site_key"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('_reCAPTCHA_site_key_', {action: 'homepage'}).then(function(token) {
...
});
});
</script>
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!
Page 1 / 1
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) {
...
});
});
```
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) {
...
});
});
```
Thank you so much!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.