1
Good afternoon
I have a select that dynamically adds row by row within a table, but my code only takes the text from the first line. I would like to take the text according to the line and pass to an Hidden input.
MY DYNAMIC SELECT
'<td>'+
'<select name="idcentrocusto[]" id="selectOption" onchange="getSelect();">'+
'<option value="">Selecione Centro Custos...</option>'+
'<?php foreach ($centrocustos as $c){?>'+
'<option value="<?php echo $c->idcentrocusto?>">'+
'<?php echo $c->centrocusto?>'+
'</option>'+
'<?php } ?>'+
'</select>'+
'</td>'+
FUNCTION WHEN CHANGING SELECT
function getSelect() {
var vai=$('#selectOption option:selected').html();
$('#centrocusto').attr('value', vai);
}
ERROR
TABLE (THIS INSIDE A SEARCH MODAL)
<table id="mytable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Un</th>
<th>Produto</th>
<th>Código</th>
<th>Qnt*</th>
<th>Delhamento Produto</th>
<th>...</th>
</tr>
</thead>
<tbody>
<?php foreach ($produtos as $produto){?>
<tr>
<td id="id"><?php echo $produto->idproduto?></td>
<td id="un"><?php echo $produto->un?></td>
<td id="produto"><?php echo $produto->produto?></td>
<td id="codigo"><?php echo $produto->codigo?></td>
<td><input style="max-width: 55px" class="form-control" id="qnt" type="text" name="qnt[]" onkeypress="return event.charCode >= 48 && event.charCode <= 57"></td>
<td><input style="width: 100%" class="form-control" id="detalhe" type="text" name="detalhe"></td>
<td><button class="add glyphicon glyphicon-plus img-circle text-primary btn-icon"></button></td>
</tr>
<?php } ?>
</tbody>
</table>
MAIN PAGE TABLE (RECEIVES SEARCH DATA)
<table id="tab" class="table table-striped table-bordered" >
<thead>
<tr>
<th id="tab_cab">Produto</th>
<th id="tab_cab">Qnt</th>
<th id="tab_cab">Detalhar Produto</th>
<th id="tab_cab">Centro de Custo</th>
<th id="tab_cab">...</th>
</tr>
</thead>
<tbody id="mytbody">
</tbody>
<tfoot>
<th>Total de Itens: <span id="counter"></span></th>
<th style="text-align: center;"> <span id="total"></span></th>
<th></th>
</tfoot>
</table>
id
is unique, can not be repeated. It would be like you search for a person by CPF or some document number and there are several people with the same IDentification. I suggest you use classes to do this, this way.– fernandosavio
Thanks for the return Fernado. How would it be that only replace the id by the class?
– frodrigues
I am formulating an answer to explain better. Just wait a little. = D
– fernandosavio
Could you put the whole table structure please?
– Alvaro Alves
Ready already posted, these data goes to the <tbody id="mytbody">
– frodrigues
Just exchange id for class, for example:
class="tab_cab"
– Sam