Eylül
Eylül

Reputation: 139

parameter of onclick function

I am trying to build a string like this:

"<a><p onclick='showDialog(" + b + ")'>Clicca qui!</p></a>"

However in this way I cannot pass the parameter.

The error is: "Uncaught SyntaxError: missing ) after argument list"

b is a string parameter.

So, how should I alter this?

Thanks!

Upvotes: 1

Views: 54

Answers (1)

Didier Aupest
Didier Aupest

Reputation: 3367

Your string b seems to contains parenthesis.

You might want to add some extra quote around your string :

"<a><p onclick='showDialog(\"" + b + "\")'>Clicca qui!</p></a>"

Upvotes: 2

Related Questions