Solved

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

Posted on 2013-01-30
4
426 Views
Last Modified: 2013-02-07
Hi,

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:

 $('.waitforrecaptcha').fancybox({
                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:
http://www.ultratrust.com/asset-protection-quiz_test2.php

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.

Thanks,
Victor

PS - here is the other part:
<span style="display:none;" id="script">http://www.google.com/recaptcha/api/challenge?k=6LdJOdQSAAAAAMvacrzREYMJxWn7FKxebfh95szZ</span>
0
Comment
Question by:Victor Kimura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Expert Comment

by:mcnute
ID: 38838916
You have some console errors.

Maybe take a look on these before debugging the other.
Bildschirmfoto-2013-01-31-um-11..PNG
0
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38840216
Hi,

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!
Working
Hope it helps u...
0
 

Accepted Solution

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

I placed this in my form:

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

And it seemed to work. I found it here:
http://stackoverflow.com/questions/3371314/how-to-reload-recaptcha-using-javascript

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.
0
 

Author Closing Comment

by:Victor Kimura
ID: 38863263
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Building a glossary into your website 9 60
allow link tag to be submit like form 15 60
asp.net mvc5 6 34
Error Handler 8 42
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

739 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