views:

124

answers:

2

I have a signup form with AJAX so that I want to refresh Recaptcha image anytime an error is occured (i.e. username already in use).

I am looking for a code compatible with ReCaptcha to reload it using JavaScript.

A: 

Try this

<script type="text/javascript" src="//www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
<script type="text/javascript">
          function showRecaptcha() {
            Recaptcha.create("YOURPUBLICKEY", 'captchadiv', {
              theme: 'red',
              callback: Recaptcha.focus_response_field
            });
          }
 </script>

<div id="captchadiv"></div>

If you calll showRecaptcha the captchadiv will be populated with a new recaptcha instance.

Tim
I do not have such a div. My code is like that: http://pastebin.com/xZ3RGeED
Ahmet Alp Balkan
you can change your code and call showRecaptcha onload? Is this helping you?
Tim
+1  A: 

it is

Recaptcha.reload();

in JavaScript if there is an already loaded Recaptcha on the window.

Ahmet Alp Balkan