Get input value within a td in the table by Jquery

0

I want to be able to capture from a Datatable table some input inside Td by means of jquery that I can take those values by means of the id or the name. In my code I search for all input type number but apparently do not know which input to take since I have 3 input type = 'number', so I want to know if it is possible to take them by the id.

Thank you ...

Code of the Table

<tr>
  <td hidden>
    <p><input 
          type="checkbox"  
          value="<?php echo $registro['id']; ?>" 
          class="unico" 
          name="colegios[]" id="<?php echo $registro['id']; ?>" 
          onclick="activarCasillaColegios(this);" checked disabled /></p>
  </td>
  <td>
    <?php  echo $registro['nombre']; ?>
  </td>
  <td>
    <input 
      type="number" id="am<?php echo $registro['id']; ?>" 
      name="am[]" step="1" min="0" 
      class="form-control"  
      value="<?php if($colegio != null) echo $colegio->getAm(); ?>" 
      onBlur="totalRacionesAm($(this));" size="5" />
  </td>
  <td>
    <input 
      type="number" id="pm<?php echo $registro['id']; ?>" 
      name="pm[]" step="1" min="0" 
      placeholder="<?php if($colegio != null) echo $colegio->getPm(); ?>" 
      class="form-control"  
      value="<?php if($colegio != null) echo $colegio->getPm(); ?>" 
      onBlur="totalRacionesPm($(this));" size="5" />
  </td>

  <td style="padding-right: 1em;">
    <input 
      type="number" name="cupos[]" step="1" min="0" 
      placeholder="<?php if($colegio != null) echo $colegio->getCupos(); ?>" 
      id="cupos<?php echo $registro['id'];?>" 
      class="form-control" <?php if($colegio != null) echo ""; ?> 
      value="<?php if($colegio != null) echo $colegio->getCupos(); ?>" 
      onBlur="totalRaciones($(this));" size="10" />
  </td>
</tr>

Jquery

function enviaFormularioPlanificacion(){
  var selectedCheckbox = new Array();
  var selectedNumber = new Array();

  var SelectContrato=$('#SelectContrato').val();
  var TipoEntrega=$('#TipoEntrega').val();

  //        CAPTURA TODOS LOS INPUNT QUE HAY EN LA TABLA
  $(tablaReceta.fnGetNodes()).find(':input').each(function (){

    // ESTA VARIABLE GUARDA TODOS LOS INPUTS "VALOR Y TYPO"
    var entradas=this;

    if(entradas.type=="checkbox"){

      if(entradas.checked){

        var number1= $("#am"+entradas).val();
        var number2= $("#pm"+entradas).val();
        var number3= $("#cupos"+entradas).val();

        selectedNumber['id']=entradas;
        selectedNumber['number1']=number1;
        selectedNumber['number2']=number2;
        selectedNumber['number3']=number3;

        selectedCheckbox.push(selectedNumber); 


      }

    }
  });
    enviaFormularioArchivoRecargaPagina('../Controller/Planificacion/GestionPlanificacion.php?tipoConsulta=<?php if($Actualizar==true){ echo 'Actualizacion';}else{ echo 'Nuevo';} ?>&Planificacion_id=<?php echo $Planificacion_id;  ?>','#FormPlanificacion','#contenido','#mensajes','Planificacion/CalendarioMinuta.php?TipoContrato='+SelectContrato+'&TipoEntrega='+TipoEntrega,'Planificación Registrada');
  $("#colegios").empty();
}
    
asked by Luis Eduardo Martinez Ocoro 15.11.2016 в 16:03
source

2 answers

1

You can also take it by:

  • class: $ ('. class'). val ();
  • id: $ ('# id'). val ();
  • name: $ ("input [name * = 'name']") .val ();
  • answered by 21.11.2016 в 06:54
    0
    var number1= $("#am"+entradas.id).val();
    

    Everything is fine, just that the id is not being assigned, but a var number1= $("#am"+entradas).val(); object.

        
    answered by 15.11.2016 в 17:53