I need to get the value of a select, that is within a cycle, and the name and ID is repeated

1

The select is inside a modal, and it is generated with a cycle, and I need in the function to know the specific value of that select

 <select id="lote" name="lote" style="width: 100%; height: 100%">
    <? while ([email protected]_fetch_array($rs3) ) {?> 
                  <option value="<? echo $registro3['ID']; ?>" name="<? echo $registro3['ID']; ?>"><? echo $registro3['NOMBRE']; ?></option>


          <? }?>
   </select>

Este este es el codigo completo del modal:

<div class="modal fade" id="myModal<? echo $registro0['ID']; ?>" role="dialog">
<div class="modal-dialog modal-sm">
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title">CREAR NUEVO REPORTE DE CAMPO</h4>
    </div>
    <div class="modal-body">
      <? include('dbconecta.php');     @mysql_query("SET NAMES 'utf8'");
      $cadbusca3="select  * FROM MA_LOTES where ID_PRODUCTOR='".$registro0['ID']."' ";
      $_SESSION['cadbusca_MODAL2']=$cadbusca3;
  $rs3 = @mysql_query($cadbusca3);
  $rows3 = @mysql_num_rows($rs3);?>


      <font>SELECCIONE EL LOTE</font>
      <select id="lote" name="lote" style="width: 100%; height: 100%">
    <? while ([email protected]_fetch_array($rs3) ) {?> 
                  <option value="<? echo $registro3['ID']; ?>" name="<? echo $registro3['ID']; ?>"><? echo $registro3['NOMBRE']; ?></option>


          <? }?>
   </select>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">CANCELAR</button>
      <button type="button" class="btn btn-primary next-step" onclick="$productor(<? echo $registro0['ID']; ?>);"  data-dismiss="modal">GUARDAR</button>
    </div>
  </div>
</div>

    
asked by GERMAN SOSA 07.09.2018 в 00:33
source

2 answers

1

Look here I leave you an example, modify yours a bit to prove it

<select id="lote" name="lote">
    <? for($x=0;$x<=10;$x++){ ?> 
        <option value="<?=$x?>" name="<?=$x?>"><?=$x?></option>
    <? } ?>
</select>
<select id="lote" name="lote">
    <? for($x=0;$x<=10;$x++){ ?> 
        <option value="<?=$x?>" name="<?=$x?>"><?=$x?></option>
    <? } ?>
</select>

<script>
    $("select").change(function(){
        alert($("select").eq(0).val());
        alert($("select").eq(1).val());
    });
</script>

What I do is use .eq() to place them inside the DOM More info link

Objects within the DOM can be a selector in order of definition (index) More info link

    
answered by 07.09.2018 / 00:40
source
1

Your problem is here:

<button type="button" class="btn btn-primary next-step" onclick="$productor(<? echo $registro0['ID']; ?>);"  data-dismiss="modal">GUARDAR</button>

You are passing as parameter the last value that has $registro3 . The solution is to grab the selected value in jQuery. Something like this:

<button type="button" class="btn btn-primary next-step" onclick="$productor($('#lote').val());"  data-dismiss="modal">GUARDAR</button>
    
answered by 07.09.2018 в 00:49