I want to make a memory game but I don't know how to pass a value of an array from PHP into JS.
I need to pass some number into a JS variable but only get the first number of the table when the user clicks.
The numbers already exist inside inside a PHP array but I need to pass the number clicked in a JS variable
PHP code (to get numbers random):
$numbers = range(0, 9);
shuffle($numbers);
HTML and PHP code (Table):
<table width="200" border="1" id="tabla" style="visibility:visible" >
<tr>
<?php foreach($numbers as $key){ ?>
<td ><a href="#" onclick="validacion()" style="color:#000; text- decoration:none;"> <div class="container"> <h1 class="box" id="text"> <?php echo $key; ?> </h1> </div> </a></td>
<?php } ?>
</tr>
</table>
JS code (Can I get ONLY the first number in the table?)
function validacion(){
var text=document.getElementById('text').innerHTML;
alert(text);
}
When I click on any number of the table I get the same first number. How would I fix this?