how to pass two PHP variables in the onclick function of the html button?

Asked

Viewed 296 times

0

echo '<button onclick="deleteVaga('.$id,$cidade.')"><i class="far fa-trash-alt" style="font-size:36px;color:#f00;"></i></button>';

in deleteVaga function, it recognizes only one variable passed, but do not know how to pass $id and $city as two parameters, to then search with ajax.

  • echo '<button onclick="deleteVaga('.$id,$cidade.')"><i class="far fa-trash-alt" style="font-size:36px;color:#f00;"></i></button>'; Alters to echo '<button onclick="deleteVaga('.$id.','.$cidade.')"><i class="far fa-trash-alt" style="font-size:36px;color:#f00;"></i></button>'; The comma is part of html and not part of php being passed.

  • I’ve tried that too and it didn’t work, there’s another way to pass these parameters?

  • No champion, a resolution of your question. In the event deleteVaga vc is passing the comma without encapsulating to be identified as an html, so just insert a deleteVaga('.$id.','.$cidade.'). See now that the comma is part of html .

  • Since the city probably has space, you need it to be in quotes, like this ('.$id.',\''.$cidade.'\')

  • Perfect Dobrychtop, worked exactly as I wanted, as I close or give this question as solved?

No answers

Browser other questions tagged

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