I want to generate a alert
by giving click
to each of the numbers in the table that is generated with the for
. The alert
works, but I want it to be the same number in the box that I click on. In this case the error is that the first value continues to be output, that is:
<?php
$indice=1;
$filas = 100;
echo "<table border= 1; id='table'>";
echo "<th> Numeros </th>";
for($i = 1; $i <= $filas; $i++){
echo "<tr>";
echo "<td>";
echo "<div id='numero' onclick='alertNumero()'>";
echo $indice++;
echo "</div>";
echo "</td>";
echo "</tr>";
}
?>
<script>
function alertNumero(){
var x = document.getElementById("numero").innerHTML;
alert(x);
}
</script>