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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:55:05+00:00 2026-05-26T06:55:05+00:00

I was just given a solution to a problem I have but I’m not

  • 0

I was just given a solution to a problem I have but I’m not really sure how to actually implement it.

$(function(){
    $.get('file1.php', function(data){
       $('#dropdown1').html( data ); 
    });

    // on change of dropdown1 populate dropdown2 with the respective data 
    $('#dropdown1').change(function(){
        $.get('file2.php',{ make: $(this).val() }, function(data){
            $(this).html( data ); 
        }); 
    }); 
}); 

Here is the question I asked
Ajax form, 2 drop downs with external source
I’m still unsure how to format file1 and file2.php as well as how to implement it into my form.
I really appreciate the advice/help . Thanks!

  • 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-26T06:55:05+00:00Added an answer on May 26, 2026 at 6:55 am

    In other words you’d like an explanation of what this JavaScript does?

    $.get('file1.php', function(data){
        $('#dropdown1').html( data );
    }); 
    

    The first AJAX call loads the output from file1.php into the element with id dropdown1 as HTML content – presumably that’s a select tag so you’d want a list of <option> elements.

    $('#dropdown1').change(function(){
        $.get('file2.php',{ make: $(this).val() }, function(data){
            $('#dropdown2').html( data );
        });
    });
    

    This second one calls file2.php?make=abc where abc is the value selected in dropdown1 and loads the content of that into dropdown2 again as HTML. So presumably again you’d want to output a list of <option> elements.

    However there’s neater ways to do this, e.g. return JSON lists of data and then assemble them into options on the client side. In particular you can then store last selected values in case the user switches between lists, switch both dropdowns to ‘loading’ or similar whilst waiting for the AJAX calls to complete, etc.

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

Sidebar

Related Questions

I have fairly simple problem but I can not think of the simple solution.
We have a JavaScript function named move which does just windows.location.href = any given
i'm trying to solve a seemingly simple problem, but just can't quite get my
actually i have found some thread that asking question like mine. but every solution
I have a problem that I tried to ask about previously, but didn't get
I think this is a simple SQL query problem, but I am just not
We've just been given the following code as a solution for a complicated search
Given this variable in tcsh: set i = ~/foo/bar.c how can I get just
This is just an example, but given the following model: class Foo(models.model): bar =
I have just started migrating my homegrown persistence framework to JPA. Given that the

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.