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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:42:13+00:00 2026-05-27T10:42:13+00:00

I have a DDL (#engine) that needs to have its option values set via

  • 0

I have a DDL (#engine) that needs to have its option values set via a MySql table based on the selected #make ddl.

I have the below script which passes to a php file – I know the php file is fine as I can output the results of the query independantly.

But, I cannot get the option values to update based on the returned array … maybe a result of using GET? It’s the first time i’m trying to return via AJAX (usually just use it to update data tables etc.)

Is there something amiss in my script?

$(document).ready(function() {

$("select#make").change(function(){
    $('#engine').find('option').remove().end(); //clear the engine ddl
    var make = $(this).find("option:selected").val(); //Need the value not the text

    $.ajax({
        url:'get-engine.php',
        type:'GET',
        data:{engine:make},
        dataType:'json',
        cache:false,
        success:function(data){


         var ddl = document.getElementById('engine');                      

         for(var c=0;c<obj.length;c++)
              {              
               var option = document.createElement('option');
               option.value = obj[c];
               option.text  = obj[c];                           
               ddl.appendChild(option);
              }


    },
        error:function(jxhr){
        alert(jxhr.responseText);

    }
    }); 

});
});

And the get-engine.php ..

$make = $_GET['engine'];

    $query= ("SELECT * FROM tb_engine where make_id='$make'");
    $result = mysql_query($query);
    $temp = array();

    while ($row = mysql_fetch_assoc($result)) {

     if(empty($temp))
     {
       $temp=array($row['engine_type']);
     }
     else
     {  
       array_push($temp,$row['engine_type']);
     }

    }
    echo (json_encode($temp));
    ?>

It so far refuses to update, can’t quite find why?

Thanks in advance for all advice

  • 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-27T10:42:14+00:00Added an answer on May 27, 2026 at 10:42 am

    you can try

    //json is the json you have recieved in the success handler
    
    $("#engine").empty();
    $.each( json, function( index, item ) {
               $("<option/>",{value:item,text:item}).appendTo("#engine");
    
            });
    

    DEMO

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

Sidebar

Related Questions

I have a table that displays rows based on a drop down list option.
I have a tool that generates a DDL script create table ATTRIBUTE_VALUE ( id
I have a table in MySQL that has 3 fields and I want to
i have a DDL that shows if a task is completed. in the table
I have a script that generates DDL scripts to define materialized views for a
Say I have an array of table DDL queries and I want to get
I have a Default.aspx that redirects to a Page1.aspx. My ddl is loaded and
I have a model that was generated for MySQL 5 but now I need
I have a DropDownList called (DDL) in ASP.net page, I want that DDL contains
I have a stored procedure that is performing some ddl dml operations. It retrieves

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.