0

Alright and my query is, How do I escape quotes in Javascript? I'm trying to alert the message with my code below. I know it won't work because it contains string in double quotes within the onClick function call and it gives the syntax error. How do I make it work? My condition is that I cannot use single quotes for parameter in my function call.

    <html>
    <head>
    <script type="text/javascript">
    function litString(vals)
    {
    alert(vals);
    }
    </script>
    </head>
    <body>

    <?php echo "Just for a Test<br/>"; ?>

    <a href="#" onClick="litString("test one")"><h2>JS String Literal</h2></a>
    </body>
    </html>

Update:

My actual intention is to make the below PHP+JS code combination work:

 echo '<li><a href="#" title="'.$res_bb['eng'].'" onClick=loadChap('.$res_bb['id'].','.$res_bb['chapters'].',"'.$res_bb['mal'].'")><font size="2">'.$res_bb['mal'].'</font></a></li>';
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jenson M John
  • 5,499
  • 5
  • 30
  • 46
  • 1
    Code in comments is unreadable. Update your question. – Barmar Apr 14 '13 at 06:19
  • @Barmar Just updated. Please have a look. Thanks. – Jenson M John Apr 14 '13 at 06:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28185/discussion-between-jenson-m-john-and-barmar) – Jenson M John Apr 14 '13 at 06:26