how can I send a variable php by onclick for a function js [closed]

0

I want to make an img html tag as a button that sends a value php to a function js and then insert it into an array, if you could help me I thank you infinitely

php

while($row = mysqli_fetch_array($result)){

    $cartaNombre = $row["Carta"];


    echo "<img  src='$cartaNombre' name='$cartaNombre' alt='no se encuentra' width='7%' class='cartas'  onclick='this.disabled = true; valor(this)'>";
}

js

   var ESEAadn = []; 
  function valor(element) {
   alert(element.getAttribute("name"));
   var value = element.getAttribute("name");
    ESEAadn.push(value);}

this is the code

    
asked by gabo luna 02.05.2017 в 07:15
source

1 answer

1

Assuming that in that onclick (onclick='this.disabled = true; valor(this)') you want to send the value you can embed code PHP in the following way:

onclick="this.disabled = true; valor('<?php echo $variables_php ?>')"

Or you could give ID to the element img and pass that ID as parameter when calling the function value within onclick and then using document.getElementById collect the data you need

    
answered by 02.05.2017 в 16:01