Reputation: 352
I want to send a string containing single and double quotes to a javascript function which then sends it to a php page as a get variable. The code is this (I've tried escaping the quotes in two ways, but none of them work):
<html>
<head>
<script type="text/javascript">
function myFunction (foo) {
window.location = "bar.php?var=" + foo;
}
</script>
</head>
<body>
<a href='javascript:myFunction("text'text"text");'>text'text"text</a><br>
<a href='javascript:myFunction("text'text"text");'>text'text"text</a>
</body>
</html>
The links just don't have any effect. Thanks!
Upvotes: 1
Views: 108
Reputation: 2049
Try this code:
echo '<a href="bar.php?var='.urlencode($value).'">text\'text"text</a><br>';
Upvotes: 1
Reputation: 8223
try urlencode()
the value before echoing it onto the page
<a href='javascript:myFunction(<?php echo urlencode($value); ?>);'><?php echo $value; ?></a>
Upvotes: 1