Pass date as parameter for Javascript function

Asked

Viewed 189 times

1

I’m trying to pass a lot of PHP to a block HTML which has a function Javascript, the problem is that it is going in numerical format, how can I solve this?

String part HTML being assembled:

$tabelaDados = "<tr><td scope='row'>'.$idDesp.'</td><td class='td-centro'><a href='#'><i class='far fa-edit'></i></a><span> </span><a href='#' onclick='apagaRegistro('.$idDesp.','.$mesAnoRef.' )'><i class='fas fa-trash-alt'></i></a></td>"

When my job is done apagaRegistro is called, the value of the second parameter comes as 0.0003984938487854787, just one example.

  • Try to put it like that on your onclick: apagaRegistro(\'' . $idDesp . '\', \'' . $mesAnoRef . '\'). You are passing without quote or quotation marks. This may be the problem.

  • @Pauloimon, gave it right. I must have skipped the class here, but what is the logic of this formatting?

  • 2

    It is the principle of declaring strings. It will always be done with quotes or apostrophes. When you pass parameter to your function of Javascript without using this format, it will interpret as Number. To backslash \' is only to escape the apostrophe in this case, because without it would give problem in the syntax of your code PHP.

  • Yeah... I really missed class...rs. Thank you very much!!!

No answers

Browser other questions tagged

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