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 7185121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:20:43+00:00 2026-05-28T18:20:43+00:00

I know this a problem with the way I have coded the plugin for

  • 0

I know this a problem with the way I have coded the plugin for dealing with multiple instances. I’m pretty sure at least one of my variables is being overwritten by each subsequent call of the plugin. Anyway, here’s the plugin code:

$.fn.extend({
dependsOn: function( $claimer ){
    $dependent = $(this);
    $claimer.change(function(){
        alert( $dependent.attr('id') );
        var $selected = $('option:selected', this);
        var pk = $selected.attr('class');

        $dependent.removeAttr('disabled');
        $dependent.find('option').each(function(){
            $hiddenOpts = $dependent.parent().find('.hiddenOptions');
            $hiddenOpts.append( $(this) );
            $hiddenOpts.find('option').each(function(){
                if( $(this).attr('ref') == pk || $(this).hasClass('empty') )
                    $dependent.append( $(this) );
            });
        });
    });
}
});

When I call $('.something').dependsOn( $('.somethingElse') );, it works fine, but if I call it again on two other items, the $dependent variable gets set to THAT element.

The point of the plugin is to keep select boxes disabled until a previous select box is changed. If I have three select boxes in a row, and I want the first one enabled, the second one dependent on the first, and the third dependent on the second, I’d call $(second).dependsOn( $(first) ), and $(third).dependsOn( $(second) ), so changing the first would then enable the second but not the third, and changing the second would then enable the third.

But with the current code, changing the first enables the third, but not the second (like I said, I think it’s because $dependent is being overwritten and set to the third thing after calling dependsOn twice).

If that’s not clear, let me know.

  • 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-05-28T18:20:44+00:00Added an answer on May 28, 2026 at 6:20 pm

    That’s because you’re not defining a new variable in the scope of dependsOf (which is done using var $dependent = blah). Instead, you’re setting the value of $(this) to a global version of $dependent.

    That’s the reason why it’s being replaced.

    Good luck 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know where to look for about this problem ... I have three
I have solved this problem, I just need to know what to do. I
I know I've solved this problem before, but I can't remember or find the
I know I've had this problem before so I'm really frustrated. I've got the
Anyone know how to solve this problem? 03-23 13:03:20.585: WARN/googleanalytics(3430): Problem with socket or
I know this question has been asked before, but I ran into a problem.
I came across this problem while preparing for an interview and curious to know
I'd like to know if there's a better approach to this problem. I want
I don't know if anyone else even has this problem, or has noticed, but
OK. This problem is doing my head in. And I don't know if there

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.