I have this php code:
$enlace = "<a href='javascript:void(0)' onClick='getComentarios('cadena de texto')'>".$gasto["comentarios"]."</a>";
It throws me an error and the chain is not passing me, I have already made thousands of attempts and I am not successful, how could I solve this?
Thanks to the help I'm getting from @phpMyGuel, now the code looks like this:
$enlace = '<a href="javascript:void(0)" onClick="getComentarios(\'cadena de texto\')">'.$gasto["comentarios"].'</a>';
The problem now comes in the following, I need to pass the value of a string variable to the javascript function and I have put the code like this but it shows an error:
$enlace = '<a href="javascript:void(0)" onClick="getComentarios(\'$gasto["comentarios"]\')">'.$gasto["comentarios"].'</a>';
In PHP the escape character is / . In your string, we can use it to use single quotes without them breaking the concatenation:
PHP
EXIT:
EDIT
The simplest way to make the function
onClick
correctly receive the value of a variable would be to separate the concatenation, as in the case of what is shown inside the link: