Neel
Neel

Reputation: 595

What needs to be escaped in an onclick event taking a string?

I'm not sure what characters need to be escaped in my string. My PHP code is giving the string parameter, but sometimes it has quotes and double quotes that I'm not sure what to do with.

onclick="eventBox('This is the string ' // " "')"

Upvotes: 1

Views: 1345

Answers (2)

Gabe
Gabe

Reputation: 50493

You will need to escape the quotes or encode them so it parses correctly.

onclick="eventBox('This is the string \' // " "')"

Otherwise there will be a parse error because of mis-matching quotes

Upvotes: 1

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143099

quotes (") should be replaced with ". And backslash (\) prepended to '.

onclick="eventBox('This is the string \' // " "')"

Upvotes: 4

Related Questions