I'm populating a table with data coming from the database, the ids are dynamic using the database id, I need to retrieve these ids with javascript, follow the code as an example.
function selecionaDactes(){
var ids = document.getElementsByClassName('editar');
gravaArray(ids);
}
function gravaArray(dados){
var array_dados = Array;
array_dados = dados;
for(var x = 0; x <= array_dados.length; x++){
if(array_dados[x].checked){
alert(array_dados[x].value);
}else{
alert('não há dados selecionados' + array_dados[x].value);
}
}
}
<table border="1">
<tr>
<td><input class="editar" type="checkbox" id="187" value="187"></td>
<td>Vasco</td>
<td><button type="button" onclick="selecionaDactes()">Editar</button></td>
</tr>
<tr>
<td><input type="checkbox" id="90" value="90"></td>
<td>Flamengo</td>
<td><button type="button" onclick="selecionaDactes()">Editar</button></td>
</tr>
<tr>
<td><input class="editar" type="checkbox" id="341" value="341"></td>
<td>Corinthians</td>
<td><button type="button" onclick="selecionaDactes()">Editar</button></td>
</tr>
<tr>
<td><input class="editar" type="checkbox" id="701" value="701"></td>
<td>Santos</td>
<td><button type="button" onclick="selecionaDactes()">Editar</button></td>
</tr>
<tr>
<td><input class="editar" type="checkbox" id="33" value="33"></td>
<td>Londrina</td>
<td><button type="button" onclick="selecionaDactes()">Editar</button></td>
</tr>
</table>
I'm new to javascript and I'm not finding the solution I've already read the documentation on this Link , but I did not find the solution