Search code examples
javascriptphpvariablesconfirm

Using a PHP variable into JS confirm() method


Here is a simple question, I have a variable (a string) that changes according to what the user actions were in the previous page, it can be 'package', 'content' etc.

Since the modification can have consequences I would like to make sure the user is aware of his action by using the confirm method that would say, "are you sure you want to delete this package" if this is a package or "are you ... this content" etc.

In my JS I did this :

var sCategorieType = $(this).closest('tr').attr('name');

And I wanted to do this :

var bConfirm = confirm("Are you sure you want to delete this'.sCategorieType.'? ");

This is not working, I would like to know why and to have an alternative.


Solution

  • Concatenation in javascript isn't the same as in PHP. In javascript you can concatenate string with the + sign.

    Try:

    var bConfirm = confirm("Are you sure you want to delete this " + sCategorieType + "? ");