Welcome Guest, Not a member yet? Register   Sign In
Interdependent select lists: full code
#1

[eluser]alvaroeesti[/eluser]
Hello,

been over a day with this. Somewhere there must be a bug. The second (there are only two) select list does not get altered, thus it gets no value when the first one changes.

Here is the full stuff, long, but very clear and commented:

VIEW

Code:
[removed]
//jquery code for source list
$(document).ready(function(){
$('#country').change(function() {
  if ($(this).val()!='') {
    $("#source").load("/CI-3/application/controllers/control_form.php",{pais_id: $(this).val()});
      }

    });

});  // end of country and city function


[removed]



<body>
  
  <?php echo form_open('control_form/add_all'); ?>
       <label for="country">Country<span class="red"></span></label>
        <select id="country" name="country_names">
            <option value="pais_id"></option>
            &lt;?php
            
                foreach($result as $row)
                {
                echo '<option value="' . $row-&gt;pais_id . '">' . $row->pais_name . '</option>';
                }
                
            ?&gt;
        </select>
        
        <label for="source">Source Language<span class="red"></span></label>
        &lt;!--this will be filled based on the tree selection above--&gt;
        <select id="source" name="source_names">
            <option value=""></option>
            
           &lt;?php
          
                        
                foreach($source as $row)
                {
                echo '<option value="' . $row-&gt;id_from . '">' . $row->from_name . '</option>';
                }
                  
           ?&gt;
            
            
        </select>
                
  &lt;?php echo form_close(); ?&gt;

CONTROLLER

Code:
public function add_all()
{

        #Validate entry form information
        $this->load->model('model_form','', TRUE);        
        $this->form_validation->set_rules('pais_id', 'Country', 'required');
        $this->form_validation->set_rules('source', 'Source language', 'required');
        
        
        # Populate the first select list by sql querying in the model. (Works well)
        $data['result'] = $this->model_form->get_state(); //gets the available countries for the dropdown
        
        # Now this should get the value selected in the first dropdown, sent from the Jquery, in the View
        $pais_id = $this->input->get_post('pais_id', TRUE); # but I am not getting anything

I know the rest is OK. The issue is somewhere above




Theme © iAndrew 2016 - Forum software by © MyBB