Good afternoon
Personal I have a select that dynamically adds row to row within a table, but my code only takes the text from the first row. I would like to get the text according to the line and move to an input hidden.
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 THE SELECT
function getSelect() {
var vai=$('#selectOption option:selected').html();
$('#centrocusto').attr('value', vai);
}
ERROR
TABLE(THISINSIDEASEARCHMODE)
<tableid="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>
TABLE MAIN PAGE (RECEIVE 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>