Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8849437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:39:07+00:00 2026-06-14T12:39:07+00:00

My goal is to load a recaptcha only when the user clicks on the

  • 0

My goal is to load a recaptcha only when the user clicks on the contact page link.

I have successfully built a site that uses navigation links to load external HTML content into the index page’s main content div based on the following function:

$('div#index_content').load($(this).attr('href') + ' #content');

When user clicks a navigation link, content from one of 6 individual .html or .php files is loaded into the index.html container:

<div id="menu">
    <ul>
        <li><a href="home.html" class="active">Home</a></li>
        <li><a href="fine_art.html" class="inactive">Fine Art</a></li>
        <li><a href="sketches.html" class="inactive">Sketches</a></li>
        <li><a href="props.html" class="inactive">Props</a></li>
        <li><a href="contact.php" class="inactive">Contact</a></li>
    </ul>
</div>

This all functions 100%.

The next step was to appended a function to the .load statement which loads a recaptcha into an empty div with id=”captcha” for my contact form:

$('div#page_content').load(($(this).attr('href') + ' #contentB'), 
   function() {
     Recaptcha.create("my public key", "captcha"); 
   }
 );

The site is still functioning at this point, but the function calling the captcha runs every time one of the navigation links is clicked, and I would like to create an if() statement that only runs the recaptcha load function if the $(this).attr(‘href’) is loading the contact.php content. In other words, I would like it to only load the captcha when the user clicks on “Contact” in the navigation bar.

I tried these two versions of my function but the captcha doesn’t load in either case:

$('div#page_content').load(($(this).attr('href') + ' #contentB'), 
   function() {
       if ($(this).attr('href') == 'contact.php') {
               Recaptcha.create("my public key", "captcha"); 
       }
   }
 );

and…

$('div#page_content').load(($(this).attr('href') + ' #contentB'), 
   function() {
       var ifContact = $(this).attr('href');
       if (ifContact == 'contact.php') {
               Recaptcha.create("my public key", "captcha"); 
       }
   }
 );

Can anyone tell me what’s wrong with my if() statement? Does the $(this).attr(‘href’) actually hold a value that can be equal to something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:39:08+00:00Added an answer on June 14, 2026 at 12:39 pm

    this in the inner and outer function does not represent the same object, store the value of href outside the inner function and use that value in the inner function.

    var href = $(this).attr('href');
    $('div#page_content').load(href + ' #contentB', 
       function() {
           if (href == 'contact.php') {
                   Recaptcha.create("my public key", "captcha"); 
           }
       }
     );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an update panel load a user control, and the goal here is
I have just recently implemented the inAppSettings kit. My goal was to load my
My goal is to have one element on initial load, this element should have
My Basic Goal A Rails app that can load new content via Ajax while
Goal: Load Ext Framework (JS File) only when needed. Problem: When loading Ext.JS at
My goal is to have text displayed normally on initial load, but when an
Goal I'm trying to load a custom class that contains a Texture2D from an
The Goal I have an employee model that I need to seed in the
My ultimate goal is to load controls as plugins, for use as DocumentContent in
My goal is to pull XML data from the API and load it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.