0

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.

2 Answers 2

1

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 + "? ");
Sign up to request clarification or add additional context in comments.

2 Comments

also OP note the quotes, you should use the double quotes as those are the ones used in the confirm - like @Daan did
Thank you this is going to help me a lot !
1

Concatenate it with "+", not with "." symbol and it'll be Okay! :)

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

Good luck!)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.