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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:09:34+00:00 2026-06-12T09:09:34+00:00

I am trying to avoid a duplicate here, as did not see my issue

  • 0

I am trying to avoid a duplicate here, as did not see my issue resolved in any of the the other ‘jQuery Select Menu’ posts around SO. Just looking to be nudged in the right direction.

I have a set of select boxes for searching through the results of cars by make and model. Naturally, The first <select> is for the Make of a car. This <select> element is being populated on page load with PHP. Once a Make is selected a makeID is passed through AJAX to retrieve the set of models relative to the selected Make.

This is all working great, my problem is that when I make multiple selections to my Make list, it never refreshes the second <select> box, thus appending models to many different makes to the second <select> box.

How can I refresh the second <select> box to only show the current results relative to the selection of the first <select> box.

My HTML:

<form method="post" action="">
  <p>
    <label for="make">Make</label>
    <select name="make" id="make">
      <?php foreach ($usedMakes->MakeResult as $MakeResult) { ?>
        <option value="<?php echo $MakeResult->makeId; ?>"><?php echo $MakeResult->makeName; ?></option>
      <?php } ?>
    </select>
  </p>
  <p>
    <label for="model">Model</label>
    <select name="model" id="model">
      <option value="" selected>Make a Selection</option>
    </select>
  </p>
  <p>
    <button name="submit" id="submit">&nbsp;Submit&nbsp;</button>
  </p>
</form>

My JavaScript:

$("#make").change(function() {
  var makeId = $(this).val();
  $.ajax({
    url: "process.inc.php?makeId=" + makeId,
    type: "GET",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      for(i = 0 ; i < data.length; i++) {
        var modelId = data[i].ModelResult.modelId;
        var modelName = data[i].ModelResult.modelName;
        var response = "<option value=\"" + modelId + "\">" + modelName + "</option>";
        var appendedData = $(response).insertAfter($("#model option:first-child"));
        $("#model option:first-child").data(appendedData);
      };
    }
  });
});
  • 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-12T09:09:35+00:00Added an answer on June 12, 2026 at 9:09 am

    Remove the options

    $("#model option").remove();  //removes all
    $("#model option:gt(0)").remove();  //leaves first item, removes the rest
    

    You should only update the once you build the whole list, not in a for loop

      var list = "":
      for (i = 0 ; i < data.length; i++) {
        var modelId = data[i].ModelResult.modelId;
        var modelName = data[i].ModelResult.modelName;
        list += "<option value=\"" + modelId + "\">" + modelName + "</option>";
      };
      var theSelect = $("#model");
      theSelect.find("option:gt(0)").remove();
      theSelect.append(list);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Also trying to avoid any use of plugins, (apart from jQuery of course, whether
Possible Duplicate: Why avoid while loops? I am trying to learn Python by following
Trying to avoid the SomethingManager trap here... Let's say I'm going to write a
I'm trying to avoid jQuery and would like to use a native solution. How
Possible Duplicate: jQuery Ajax always returns “undefined”? I'm trying to come up with a
I'm trying to avoid duplicate data on my Database, so I made UNIQUE columns,
I'm trying to avoid having to create duplicate images (one thumbnail one full size)
I am trying to avoid C6011 warning because an abort function is calling exit().
I'm trying to avoid the use of magic strings as much as I can,
I'm trying to avoid the memory leak in PHP. When I create a object

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.