Link to home
Start Free TrialLog in
Avatar of Vadymus
Vadymus

asked on

Escape Character Help: onclick='myFunction(1,"+iParseThisString+")'

Hello,
If you know about how to use escape character, I think it should be very easy for you to help me.
I need to parse string variable within single quotes like this:

var iParseThisString = "Hello";
document.write ("<table><tr><td onclick='myFunction(1,"+iParseThisString+")'>Link</td></tr></table>");

THE PROBLEM IS: iParseThisString as a string cannot be parsed.
Error is "Hello is not defined"
Character \ must be used, but how?..................

Thanks.
Avatar of Roonaan
Roonaan
Flag of Netherlands image

I would go with:

document.write ("<table><tr><td onclick=\"myFunction(1,'"+iParseThisString+"')\">Link</td></tr></table>");

-r-
Avatar of Vadymus
Vadymus

ASKER

Unfortunately, that did not work for me.
To be more precise, this is my code:

var iParseThisString = "Hello";
var iParseThisNum = 553;

array("<table><tr><td onclick='myFunction("+iParseThisNum+","+iParseThisString+",1)'>Link</td></tr></table>");

Note: iParseThisNum works well because it is a number, but iParseThisString does not
Thank you for your help.
Avatar of Vadymus

ASKER

Also, it works well if I write the string as it is without variable:

array("<table><tr><td onclick='myFunction("+iParseThisNum+",\"Hello\",1)'>Link</td></tr></table>");

But how to make that "Hello" be a string variable instead?
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vadymus

ASKER

marvelous!