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

Posted on 2006-05-18
Last Modified: 2008-03-10
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?..................

Question by:Vadymus
    LVL 49

    Expert Comment

    I would go with:

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


    Author Comment

    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.

    Author Comment

    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?
    LVL 49

    Accepted Solution

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


    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now