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>';
"`. – Barmar Apr 14 '13 at 06:15