I have a table with some data, I need to get the values of each input of each selected checkbox, and store it in an array or a json to be able to send it with ajax. The question is that I can go through the selected checkbox but I can not get the values and store any suggestions? This is my view
function save(){
var elegidos = $('input[type=checkbox]:checked');
var cantidad = [];
elegidos.each(function(){
cantidad.push($(this).attr('cantidad'));
})
console.log(cantidad);
}
<table id="detalles" class="table table-responsive">
<thead>
<tr>
<td>Guardar</td>
<td>Cantidad</td>
<td>Cantidad por Recepcionar</td>
<td>Cantidad OC</td>
<td>Codigo</td>
<td>Nombre</td>
<td>Nro OC</td>
<td>Sub-inv</td>
<td>Ubicacion</td>
<td>Fecha Vigencia</td>
<td>Nro Lote</td>
</tr>
</thead>
<tbody>
@if(!empty($po_lines_all))
@foreach($po_lines_all as $key => $po)
<form class="detalles">
<tr id="dat-{{ $key }}">
<td><input type="checkbox" name="val[]" id="val" class="val" ></td>
<td><input type="number" name="cantidad[]" class="cantidad" style="width:100%" value=""></td>
<td><input type="number" name="cantidad_recepcion[]" readonly="readonly" class="cantidad_recepcion" style="width:100%" value="{{ $po->quantity_ordered - $po->quantity_delivered }}"></td>
<td><input type="number" style="width:100%" name="cantidad_oc[]" readonly="readonly" class="cantidad_oc" value="{{ $po->quantity }}"></td>
<td>
<input type="text" style="width:100%" name="codigo[]" readonly="readonly" class="codigo" value="{{ $po->codigo }}">
</td>
<td>
<input type="text" style="width:100%" name="nombre[]" readonly="readonly" class="nombre" value="{{ $po->nombre }}">
</td>
<td style="display:none;"><input type="text" value="{{ $po->item_id }}" name="item_id[]" class="item_id" style="display:none;"></td>
<td><input type="text" name="oc[]" class="oc" readonly="readonly" style="width:100%" value="{{ $po->segment1 }}"></td>
<td>
<select name="sub_inv[]" id="sub_inv" class="sub_inv">
<option></option>
@foreach($sub_inv as $sub)
<option value="{{ $sub->id }}" id="subinventory_id">{{ $sub->name }}</option>
@endforeach
</select>
</td>
<td>
<select name="locator[]" id="locator" class="locator" style="width: 100%;">
<option></option>
</select>
</td>
<td><input type="date" style="width:100%" name="fecha_vigencia[]" class="fecha_vigencia"></td>
<td><input type="text" name="nro_lote[]" class="nro_lote" style="width:150%"></td>
<td style="display:none;"><input type="text" style="display:none;" name="categoria_id[]" class="categoria_id" value="{{ $po->category_id}}"></td>
<td style="display:none;"><input type="text" style="display:none;" name="quantity[]" class="quantity" value="{{ $po->quantity }}"></td>
<td style="display:none;"><input type="text" style="display:none;" name="unit_meas_lookup_code[]" class="unit_meas_lookup_code" value="{{ $po->unit_meas_lookup_code }}"></td>
<td style="display:none;"><input type="text" style="display:none;" name="po_header_id[]" class="po_header_id" value="{{ $po->po_header_id }}"></td>
<td style="display:none;"><input type="text" style="display:none;" name="po_line_id[]" class="po_line_id" value="{{ $po->po_line_id }}"></td>
<td style="display:none;"><input type="text" style="display:none;" name="po_distribution_id[]" class="po_distribution_id" value="{{ $po->po_distribution_id }}"></td>
<td style="display:none;"><input type="text" style="display:none;" name="primary_uom_code[]" class="primary_uom_code" value="{{ $po->primary_uom_code }}"></td>
<!-- campos para comparar valores -->
<td style="display:none;"><input type="text" style="display:none;" name="stock_enabled_flag[]" class="stock_enabled_flag" value="{{ $po->stock_enabled_flag }}"></td>
<td style="display:none;"><input type="text" style="display:none;" name="inventory_item_status_code[]" class="inventory_item_status_code" value="{{ $po->inventory_item_status_code }}"></td>
<td style="display:none;"><input type="text" style="display:none;" name="mtl_transactions_enabled_flag[]" class="mtl_transactions_enabled_flag" value="{{ $po->mtl_transactions_enabled_flag }}"></td>
</form>
</tr>
@endforeach
@else
<tr><td colspan="10" class="alert alert-danger" style="text-align:center;">No existe registro</td></tr>
@endif
</tbody>
</table>