I would like to know how to maintain the ability to have both single and double quotes in text that I am passing to a JavaScript function with callFunction()? All three cases below appears to be failing.
Mixing the single and double quotes will work but I would like to be able to use both single and double quotes in my text blocks. It is curious why the browser is evaluating html special characters before passing it to the Javascript function.
Thanks, Robin
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function callFunction(text){
alert(text);
}
</script>
</head>
<body>
<!--This will not work due to '-->
<a href="javascript: callFunction('Robin's Text')">Robin's Text</a>
<br />
<br />
<!--And this will not work due to "-->
<a href='javascript: callFunction("Robin"s Text")'>Robin"s Text</a>
<br />
<br />
<!--Trying with a slash but not working either-->
<a href='javascript: callFunction("Robin\'s Text")'>Robin's Text</a>
</body>
</html>