Tengo una tabla llamada "drivers" con 3 campos "id", "name" y "mob".
Tengo 2 desplegables.
Por favor, eche un vistazo a mi código existente e intente resolver mi problema. Aquí está mi código:
LO SIENTO, no puedo pegar el código aquí debido a un error de desbordamiento de pila. He pegado código en este enlace: aquí
Debe usar ajax iniciado por la función de cambio en el cuadro de selección de controladores. Debe tener un aspecto como este :
<select onchange="getval(this.value)"> <option value="1">One</option> <option value="2">Two</option> </select>En tu escenario debería ser:
<select name="dname" class="form-control" onchange="getval(this.value)"> // <?php foreach($results_drivers as $row) { echo '<option value="'.$row->id.'">'.$row->name.'</option>'; } ?> </select>Luego escribe una función jquery:
function getval(driverid){ $.ajax({url: "controller/newmethod/"+driverid, success: function(result){ //now populate the mobile number in the select box. }}); }en su controlador:
Public function newmethod($id){ $driver_data = //query to get data from your table with where cluase /// where id = $id //and then get the data in format you like, let say array print_r($driver_data);exit; } Now in jquery , you have data of driver in result variable that is passed as a parameter in function . now that should be easy for you . if you still have question or problem implementing it , let me know. It is easy task and you are going to use it in future a lot of times. Thats why I want you to do it your self and just telling you the methodology.// también puede usar id y en la función jquery
<select name="dname" class="form-control" id="selectid"> foreach($results_drivers as $row) { echo '<option value="'.$row->id.'">'.$row->name.'</option>'; } </select> get value using select box id, post driver id in controller method using ajax function call model method in your controller method and put this driver id in your model method's parameter and fetch reult data in success funtion $('#selectid').on('change', function() { var value = this.value; var val; var url = <?php echo base_url('admin/new_booking_validation'); ?> $.ajax({ url: url, type: 'POST', data: { val: value}, success: function(result){ //now populate the mobile number in the select box. }}); })Yo haría esto:
Ahora mi amigo, creo que tu pregunta cambia con eso. ¿Tengo razón?
¡Espero que ayude!