How to use double-quotes string within single quotes?

Why does this code fail? I want to have a double-quoted string within the alert!

Please note that I cannot change the: onclick="alert('....')" format!
<html>
<body>
<input type="button" value="alert" onclick="alert('This is\"s a test!')">
</body>
</html>

Open in new window

__php__Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

__php__Author Commented:
hmm.. it fails in the "code" section as well! I'll try posting here:

<html>
<body>
<input type="button" value="alert" onclick="alert('This is\"s a test!')">
</body>
</html>
0
prunckleCommented:
__php__

... depending on the function, you may need to add a semicolon at the end.....
For the \"s escape sequence...it it necessary to the final code?  because it seems that you've escaped the double quote properly...
<html>
<body>
<input type="button" value="alert" onclick="alert('This is\"s a test!');">
</body>
</html>

Open in new window

0
Pratima PharandeCommented:
<input type="button" value="alert" onclick='alert("This is\"s a test!");'>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

pwrBallCommented:
This should work fine:

use &quot;

<html>
<body>
<input type="button" value="alert" onclick="alert('This is&quot;s a test!')">
</body>
</html>
0
flyingCoyoteCommented:
Two problems...first one is a typo in line 3:

3. onclick=s"alert(

...should be:

3. onclick="alert


To fix the other problem, reverse the usage of quotes:

"alert('This is\" a test!')"

...becomes:

'alert("This is\" a test!")'

Full working version posted below in snippet.
<html>
<body>
<input type="button" value="alert" onclick='alert("This is\" a test!")'>
</body>
</html>

Open in new window

0
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.