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

  • Home
  • SEARCH
  • 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 228421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:40:51+00:00 2026-05-11T19:40:51+00:00

I have been stuck on this problem for almost 2 days now, consider the

  • 0

I have been stuck on this problem for almost 2 days now, consider the following code:

‘.country-select’ occurs twice in the form ( input),

$('.branch-row').hide();
$('.country-select').change(function(){
    console.log($(this));
    country_select = $(this);
    $.get('get_country_branches.php',
        'country=' + $("'#" + country_select.attr('id') + " option:selected'").val() + '&field=' + $(':input:eq('+($(":input").index(country_select) + 1) +')').attr('name'),
        function(html){
            $(':input:eq('+($(":input").index(country_select) + 1) +')').html(html);
            //debug 1
            console.log(country_select);
            country_select.parent().parent().next().show();
        },
        'html'
    );

}).change();
//debug 2
console.log(country_select);

the output from the debug 1 are both the same object:

[select#pays-dem.country-select]
[select#pays-dem.country-select]

however the output from debug 2 is correct:

[select#pays-enlev.country-select]
[select#pays-dem.country-select]

It seems that the problem lies within the $.get() AJAX function and the country_select object.. Any idea wtf is going on?

  • 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-11T19:40:51+00:00Added an answer on May 11, 2026 at 7:40 pm

    By not putting var in front of the country_select variable, it’s being bound in the global space rather than local to the function. Also, I don’t think you need to requery to get the selected value of the select. Using val() ought to be enough. I’d try to simplify the selection of what I think is the next input following the select. Try something like this:

    $('.country-select').change(function(){
        console.log($(this));
        var country_select = $(this);
        $.get('get_country_branches.php',
            'country=' + country_select.val() + '&field=' + country_select.next('input:first').attr('name'),
            function(html){
                country_select.next('input:first').html(html);
                //debug 1
                console.log(country_select);
                country_select.parent().parent().next().show();
            },
            'html'
        );
    
    }).change();
    

    BTW, this will break the console.log following the function since the variable is no longer in the global scope.

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

Sidebar

Related Questions

I have been stuck on this problem for days and am about the crack...
Have been stuck with this issue for a few days now, and really need,
I've been stuck with this problem for over a week now. Hopefully some one
I've been stuck with this problem from a couple of days and I can't
The rails books and web pages I've been following have all stuck to very
I've been working on this problem for awhile now, and haven't been able to
i'm using css to make a webpage and i have been stuck on this
I have been stuck on this one for a while - I couldn't figure
I have some problem with the injecting of my cookie into login.php page. This
I've been stuck since several days on my bluetooth application. Its role is 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.