Hello
I'm trying to send a value to a function by clicking the button, what could be wrong?
echo"<button id=".$nome." onclick='produtoComprado(/'".$detalhes."/')'>".$nome."</button>";
Thank you
Hello
I'm trying to send a value to a function by clicking the button, what could be wrong?
echo"<button id=".$nome." onclick='produtoComprado(/'".$detalhes."/')'>".$nome."</button>";
Thank you
When you use double quotation marks "
, there is no need to do concatenation in this way, you can just place the variable, and if you need to put quotation marks inside the text, just use the backslash before \"
to escape, the code gets cleaner and makes life easier.
echo "<button id=\"$nome\" onclick=\"produtoComprado('$detalhes')\">$nome</button>";
Follow the example by running: link
To learn more about the difference in quotation marks: Difference between single and double quotation marks in PHP
It was missing two simple quotes when setting the button id, test:
echo "<button id='".$nome."' onclick='produtoComprado(/'".$detalhes."/')'>".$nome."</button>";