Load select dependents in Dropdown in update with Codeigniter

0

Good day, it turns out that I want a page of data update in which I load dependent select with jQuery and Ajax (which I already have it preconfigured in another page where I do it as a new record ~ and the information is load of the db).

I share the view of the page where I add the new information:

<div class="form-group"><!-- desplegar paises -->
                                              <label for="pais">* Pais</label>
                                              <select class="form-control select2" name="pais" id="country">
                                                  <option value="">Seleccionar pais</option>
                                                  <?php if(!empty($countries)){ foreach($countries as $row){ echo '<option value="'.$row['id_pais'].'">'.$row['nombre_pais'].'</option>';} }else{echo '<option value="">Pais no disponible</option>';}
                                                  ?>
                                              </select>
                                          </div>
                                          <div class="form-group"><!-- desplegar estados -->
                                              <label for="estado">* Departamento</label>
                                              <select class="form-control select2" name="estado" id="state">
                                                  <option value="">Seleccione pais primero</option>
                                              </select>
                                          </div>
                                          <div class="form-group"><!-- desplegar ciudades -->
                                              <label for="municipio">Municipio</label>
                                              <select class="form-control select2" name="municipio" id="city">
                                                  <option value="">Seleccione estado primero</option>
                                              </select>
                                          </div>

When I want to update the information on the data update page I have this code, which I add in the value of the input:

<?php echo !empty($post['nombre_primero'])?$post['nombre_primero']:''; ?>

With this I have no problem.

But I can not formulate to load the dependent and not dependent selects in the same way that I do with the input when updating the information.

Send capture to see the result so far:

Thank you in advance.

    
asked by Edwin Vasquez 02.09.2018 в 05:39
source

1 answer

0

Edwin, without the AJAX code and the Jquery is hard to help, but the selects do not work in the same way as the inputs . A select has option elements in for each option and the selected option is marked with selected .

Here I leave an example of the structure so you can rethink the jQuery or share it so we can give you a better solution.

<select>
  <option>Monday</option>
  <option>Tuesday</option>
  <option>Wednesday</option>
  <option>Thursday</option>
  <option selected>Friday</option>
  <option>Saturday</option>
  <option>Sunday</option>
</select>
    
answered by 02.09.2018 в 09:31