Concatenation in function checks

Asked

Viewed 32 times

0

$linkBloquear = '
  <a href=
      "?produtos&bloquear&idProdutos=' . $produtos->getIdProdutos() . '"
      onclick="return verifica(' . $mensagemBloquear . ');" 
   >
' . $imagemBloquear . '
</a>';

I posted this way to facilitate the visualization.

I’m having trouble with the job checking

The way it is

(' . $mensagemBloquear . ')

Something like:

return verfica (Tem mesmo que verificar?)

And it’ll be a mistake;

I tried to:

(\"' . $mensagemBloquear . '\")

and comes out something like:

return verfica (\Tem mesmo que verificar?\)

How do I correct that?

3 answers

0


The problem was in the quotation marks here:

onclick="return verifica(\'' . $mensagemBloquear . '\');"

Instead of putting single quotes escapes was putting double quotes:

onclick="return verifica(\"' . $mensagemBloquear . '\");"

0

In Javascript you have 3 bookmarks String, usa string template "`".

onclick="return verifica(`' . $mensagemBloquear . '`);" 

0

Use something like, use this way of concatenating.

$linkBloquear = "<a href='?produtos&bloquear&idProdutos=123' onclick='return verifica(\"{$mensagemBloquear}\");'>Teste</a>";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.