Reputation:
I am a attempting to pass a URL inside a javascript
onclick
function but it returns missing )
error on console log, i experiment on it and found out that the URL contains special characters and sometimes spaces that escape the onclick
event.
I am getting the url from a PHP
script
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
and passing it on a onclick event
<a href="#" class="btn btn-primary" id="main" onclick="getContent(<?php echo $actual_link;?>);">Content 1</a>
My question is how to pass a url text inside a javascript function.
Upvotes: 0
Views: 35
Reputation: 922
Your missing a ''
inside the getContent
function.
onclick="getContent('<?php echo $actual_link;?>');">
Upvotes: 0
Reputation: 171669
You need quotes around the php output in order to pass string to function:
onclick="getContent('<?php echo $actual_link;?>');">
// ^^ ^^
Upvotes: 2