How to load <script></script> at specific <div class='loadrecaptcha'>?

Posted on 2013-01-30
Medium Priority
Last Modified: 2013-02-07

I'm trying to load or execute this <script>:

<script type='text/javascript' src='http://www.google.com/recaptcha/api/challenge?k=6LdJOdQSAAAAAMvacrzREYMJxWn7FKxebfh95szZ'></script>

at this location:

<div class="right loadrecaptcha"></div>

But I'm using fancybox and I believe I have to load it in afterLoad like:

                afterLoad: function(current, previous) {

                    var script = $('span#script').html();
                    if (script.length) {
                        $('.loadrecaptcha').html('<sc'+'ript type="text/javascript">' + script + '</sc'+'ript>');

Here is my test page:

click on the second "Submit" button. The google recaptcha isn't currently showing for some reason. Oddly, it was working before (without any changes to code and then all of a sudden the captcha stopped displaying. So thought of upgrading to the latest fancybox code but the problem still persists.

Anyway, I'm trying to load the script on the $.fancybox.afterLoad to see if this works.


PS - here is the other part:
<span style="display:none;" id="script">http://www.google.com/recaptcha/api/challenge?k=6LdJOdQSAAAAAMvacrzREYMJxWn7FKxebfh95szZ</span>
Question by:Victor Kimura
  • 2
LVL 11

Expert Comment

ID: 38838916
You have some console errors.

Maybe take a look on these before debugging the other.
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38840216

I tested it in Chrome browser and seems to be working fine!

When i click on Submit2 button, i'm able to see the Captcha Control!

Check the below image for proof!
Hope it helps u...

Accepted Solution

Victor Kimura earned 0 total points
ID: 38846666
Thank you, fellas!

I placed this in my form:

$div_id_recaptcha = 'loadrecaptchadiv';
echo '
                                    <script type="text/javascript">
                                        Recaptcha.create(".$public_key.", "'.$div_id_recaptcha.'", {
                                                theme: "red",
                                                callback: Recaptcha.focus_response_field

And it seemed to work. I found it here:

I didn't or couldn't find the documentation for this on the Google Recaptcha pages though.

The $div_id_recaptcha is where you want to load the captcha. Hope this helps others.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question