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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:28:27+00:00 2026-06-14T03:28:27+00:00

I am having trouble getting ajax to work with my dynamic combo box. First

  • 0

I am having trouble getting ajax to work with my “dynamic combo box.” First here is the code:
The View:

<?php echo form_open('control_form/add_all'); ?>
    <label for="make">State<span class="red">*</span></label>
    <select id="make" name="make" >
        <option value=""></option>
        <?php
        foreach($makeOptions->result() as $make){
            echo '<option value="' . $make->make_id . '">' . $make->make . '</option>';
        }
        ?>
    </select>
    <label for="model">City<span class="red">*</span></label>
    <!--this will be filled based on the tree selection above-->
    <select id="model" name="model"> 
        <option value=""></option>
    </select>
    <label for="f_membername">Member Name<span class="red">*</span></label>
    <!--<input type="text" name="f_membername"/>-->
    <?php echo form_close(); ?>

The View Controller:

    function dropDown(){
         if ($this->ion_auth->requireAdmin())         
        $data = array('title' => 'DropDown', 'main_content' =>     'admin/dropDown');        
        $data['makeOptions'] = $this->vehicle_model->getMake(Null, Null);
        $data['modelOptions'] = $this->vehicle_model->getModel(Null, Null, NULL, Null);            
        $this->load->view('admin/includes/template', $data);          
}

The Ajax controller:

   function get_model($make){    
    header('Content-Type: application/x-json; charset=utf-8');
    echo(json_encode($this->vehicle_model->getModelByMake ($make)));
} 

The Jquery:

$('#model').hide();
 $('#make').change(function(){
var make_id = $('#make').val();
if (make_id != ""){
    var post_url = "http://pulsedrivers.com/admin/get_model/" + make_id;
    $.ajax({
        type: "POST",
         url: post_url,
         success: function(models) //we're calling the response json array 'cities'
          {
            $('#model').empty();
            $('#model').show();
               $.each(models,function(model_id,model) 
               {
                var opt = $('<option />'); // here we're creating a new select option for each group
                  opt.val(model_id);
                  opt.text(model);
                  $('#model').append(opt); 
            });
           } //end success
     }); //end AJAX
} else {
    $('#model').empty();
    $('#model').hide();
}//end if
}); //end change 

The Model (used by get_model controller):

function getModelByMake ($make, $tree = null){
    $this->db->select('model_id, model, make_id');

    if($tree != NULL){
        $this->db->where('make_id', $make);
    }
        $this->db->where('make_id', $make);
    $query = $this->db->get('model');
    $models = array();

    if($query->result()){
        foreach ($query->result() as $model) {
            $models[$model->model_id] = $model->model;
        }
        return $models;
    } else {
        return FALSE;
    }
}

The view contains two dropdowns, one displays makes, the other the corresponding models. The models are not showing up after a make is selected. Firebug does not show any errors during the process.

Things already checked: jquery works, the script loads.

The controller get_models returns an array like this 1:Corvette, 2:Camaro so that seems its works correctly as well.

Any help is gratefully appreciated, 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-06-14T03:28:29+00:00Added an answer on June 14, 2026 at 3:28 am

    Turns out my script was incorrect. For future reference to fellow noobies like myseleft to jquery and ajax. If you want your script to start on page open, wrap your code with this function:

     $(document).ready(function(){
     });
    

    Also, Codeigniter related, turn CSFR Token to false. (development purposes only, once you go live you will need to set it to true for security reasons). I will now need to look up how to use my script with CSFR token set to true.

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

Sidebar

Related Questions

I'm having trouble getting a response from my php jquery / json / ajax.
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
Im having some trouble getting Ajax.ActionLink to work how I expect. In /views/layout/_Layout.cshtml I
I am having trouble getting an .on 'click' function to work upon AJAX loaded
I'm having trouble getting the follow code to work in Internet Explorer, it doesn't
I'm having trouble getting the Jquery Cycle plugin to work. My code is below.
I am having trouble getting a success: function(){} working - the ajax code I
i am having trouble getting this XMLHttpRequest to work properly, this is my first
I'm having trouble getting ajax to work with jquery and codeigniter. I've followed multiple

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.