Problems with nested combo box

0

I have a combobox nested to another combobox and it works only on the first line; it turns out that I want the combobox to work for me in the other rows (below) that are the result of a request to the database, I hope I have explained, below a fragment of the code:

<script language="javascript">
$(document).ready(function(){
   $("#noap").change(function () {
           $("#noap option:selected").each(function () {
            elegido3=$(this).val();
            $.post("caso2.php", { elegido3: elegido3 }, function(data){
            $("#noap2").html(data);

            });            
        });
   })
});


</script>

And the html and php code here:

  <?php //while($row = mysql_fetch_array($result))
          $res = mysqli_query($connex, $ret);
          while($row = mysqli_fetch_assoc($res))
          {?>



          <tr id="status" name="status">
            <td><form  method="post" autocomplete="off" class="para_envio" onsubmit="return false" >
             <td><input type="hidden" name="id[]"  size="10" value="<?php echo $row['id']?>" readonly /><input type="hidden" name="bl3[]"  size="10" value="<?php echo $row['bl3']?>" readonly />
              <td><input type="text" name="cod_it[]"  size="10" value="<?php echo $row['cod_it']?>" readonly /></td>


             <td><input type="text" name="noap2[]"  size="5" value="<?php echo $row['noap2']?>" /></td>


             <td><input type="text" name="uni_ca[]"  size="5" value="<?php echo $row['uni_ca']?>" readonly/></td>
              <td><input type="text" name="pla_ca[]" size="5" value="<?php echo $row['pla_ca']?>" readonly /></td>
             <td><input type="text" name="num_int[]"  size="5" value="<?php echo $row['num_int']?>" readonly/></td>
              <td><input type="text" name="tipo_pa[]" size="8" value="<?php echo $row['tipo_pa']?>" readonly /></td>

              <td><select name="noap" id="noap" >  
                <option value="<?php echo  $row['noap'];?>" selected="selected"><?php echo $row['noap'];?> </option>  
                <?php
                $sql3 = 'SELECT * FROM conductor ORDER BY nomapell';
            $result3 = mysqli_query($connex, $sql3);
            if (mysqli_num_rows($result3) > 0) {

            while($row3 = mysqli_fetch_assoc($result3)) {


?>
                <option value="<?php echo  $row3['nomapell']; ?>" > <?php echo  $row3['nomapell']; ?>  </option>
                <?php  
       }
            }
     ?>
    
asked by Leonardo Rodríguez 18.04.2018 в 21:58
source

1 answer

0

Starting from your example you must first load your first select or combobox once the user selects an option send to find that selection and load the second select and so on example:

there you select the state

    <div>Selecciona Estado : <select name="cbx_estado" id="cbx_estado">
        <option value="0">Seleccionar Estado</option>
        <?php while($row = $resultado->fetch_assoc()) { ?>
            <option value="<?php echo $row['id_estado']; ?>"><?php echo $row['estado']; ?></option>
        <?php } ?>
    </select></div>

With this we verify and obtain the value of the select and load a new combobox based on the selection

        $(document).ready(function(){
            $("#cbx_estado").change(function () {

                $("#cbx_estado option:selected").each(function () {
                    id_estado = $(this).val();
                    $.post("getMunicipio.php", { id_estado: id_estado }, function(data){
                        $("#cbx_municipio").html(data);
                    });            
                });
            })
        });

here the new combobox is assigned

<div>Selecciona Municipio : <select name="cbx_municipio" id="cbx_municipio"></select></div>

I hope I have helped you!

    
answered by 18.04.2018 в 22:42