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

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here is the YUI documentation for Dom methods. Yahoo! UI… May 12, 2026 at 12:19 am
  • Editorial Team
    Editorial Team added an answer It's not that hard to get familiar enough with the… May 12, 2026 at 12:19 am
  • Editorial Team
    Editorial Team added an answer You really only need to store the session ID: as… May 12, 2026 at 12:19 am

Related Questions

I know it's not sporting asking for this kind of help, But I've been
I have set up a dialog with several tabs. One of these contains twenty
There are plenty of performance questions on this site already, but it occurs to
I have a WCF Service and an application with a Service Reference to it,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.