2
I want to know how many lines I have in each and which line will be modified, for that I want to add increment in id="id_tec_pag'+id_tec_pag+'[]"
. And that with each block change this counter will restart.
Body:
html += ' <tbody>';
html += ' <tr class="linhas'+cdRegiao+'">';
html += ' <input type="hidden" id="id_tec_pag'+id_tec_pag+'[]"/>';
html += ' <td class="col-md-3"><input type="text" name="nome'+cdRegiao+'_tec[]"/></td>';
html += ' <td class="col-md-3"><input type="text" name="email'+cdRegiao+'_tec[]"/></td>';
html += ' <td class="col-md-1"><input type="text" name="telefone'+cdRegiao+'_tec[]"/></td>';
html += ' <td class="col-md-2"><input type="password" name="senha1'+cdRegiao+'_tec[]"/></td>';
html += ' <td class="col-md-2"><input type="password" name="senha2'+cdRegiao+'_tec[]"></td>';
html += ' <td class="col-md-1"><button type="button" class="removerCampo"><i class="fa fa-close fa-lg"></i> <?=TXT_BOTAO_EXCLUIR?></button></td>';
html += ' </tr>';
html += ' </tbody>';
html += ' </table>';
html += ' </div>';
html += ' </div>';
$('#div-regioes').append(html);
adicionaCampo(cdRegiao);
JS:
function adicionaCampo(codigo) {
//$(".adicionarCampo").unbind("click");
$(".adicionarCampo").on("click", function () {
novoCampo = $("tr.linhas"+codigo+":first").clone();
novoCampo.find("input").val("");
novoCampo.insertAfter("tr.linhas"+codigo+":last");
removeCampo(codigo);
});
}
You want the index (line number) or id on the line?
– adventistaam
Try to change
<input type="hidden" id="id_tec_pag'+id_tec_pag+'[]"/>';
for<td style='display: none' class="id">id_tec_pag</d>
. Ai Voce takes this id in jquery with Closest.var row = $(this).closest('tr'); var id = row.find('.id').text()
– adventistaam
Any way would help me, for example, I have a button that adds a div, and it starts with a region id =1, I want to know how many id_tec_pag the user added, when he adds another region, in the case of region = 2, I want to know how many id_tec_pag you have in region 2 and so on.
– joão victor fernandes
How you add this item to the table?
– adventistaam
I was adding only Rows, but without differentiating which is which, so I can’t update the information when the user does editing.
– joão victor fernandes
adds a data-id in the field and ai recovers the value of the data-id and sum to obtain the n°of the new id.
– Will Knippelberg