Foros del Web » Programando para Internet » PHP »

No carga primer dato

Estas en el tema de No carga primer dato en el foro de PHP en Foros del Web. Saludos amigos. Tengo el código de un select dependiente, al seleccionar algún dato (idiomas), carga los datos en un nuevo select (horarios). Pero no funciona ...
  #1 (permalink)  
Antiguo 29/03/2019, 15:30
 
Fecha de Ingreso: marzo-2011
Mensajes: 58
Antigüedad: 13 años
Puntos: 0
No carga primer dato

Saludos amigos.

Tengo el código de un select dependiente, al seleccionar algún dato (idiomas), carga los datos en un nuevo select (horarios). Pero no funciona totalmente, el primer dato de la lista no lo toma, a partir del segundo dato funciona bien. Me podrían ayudar a detectar el error? Espero me haga entender. Gracias.

Este es el formulario:

Código HTML:
<html><head> 
<title>Agregar fila de campos DINAMICOS</title> 
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    $(".soc").change(function(){
            var tr =  $(this).parent().parent();
           //alert($('.soc').val());
            soc = $(this).val();
            $.post("getIdiomas.php", { soc: soc }, 
                         function(data){
                         tr.find("#term").html(data); 
            });
   })
    
    $("#adicional").on('click', function(){
      var row = $("#tabla tbody tr:eq(0)").clone(true).removeClass('fila-fija');
      row.find('.term').empty(); 
      row.appendTo("#tabla tbody")
    });
    
    $(".eliminar").on("click",function(){
      var parent = $(this).closest("tr").remove();
    });

}); 
</script>
   </head>
   <body>
      <table align="center" class="table bg-info" id="tabla">
         <thead>
            <tr>
               <th>IDIOMAS</th>
               <th>HORARIOS</th>
            </tr>
         </thead>
         <tbody>
            <tr class="fila-fija">
               <td>
                  <select class="soc" name="soc[]">
                     <option value="NULL">Seleccionar</option>
                     <option value="1">ingles</option>
                     <option value="2">frances</option>
                     <option value="3">portugues</option>
                  </select>
               </td>
               <td><select name="term[]" class="term" id="term"></select></td>
               <td class="eliminar"><input type="button" value="-"/></td>
            </tr>
         </tbody>
      </table>
      <div class="btn-der"><button id="adicional" name="adicional" type="button" class="btn btn-warning">+</button></div>
   </body>
</html> 
Este es el archivo del segundo select (archivo getIdiomas.php):

Código PHP:
<?php
include('conexion.php');
$soc $_POST['soc'];
$query="SELECT cod_hor,horario from horario where cod_hor='$soc'"
$result=$mysqli->query($query);
$html "<option value=''>Seleccionar</option>";
     
while ((
$fila mysqli_fetch_array($result)) != NULL) {
$html.= "<option value='".$fila['cod_hor']."'>".$fila['horario']."</option>";
}
echo 
$html
?>

Última edición por andvilla07; 29/03/2019 a las 16:09

Etiquetas: ajax, jquery, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:18.