1

I am trying to pull a string variable into my javascript function from a PHP file and am being returned: Uncaught SyntaxError: Unexpected end of input.

I have tried to use onclick="showContent('home')" but this does not load the page at all. I assumed that placing home in parentheses would act as a string parameter and fill that variable in the javascript function.

In my header.php: echo "<img src='../images/home.png' onclick='showContent('home')' alt='Home' /></a>";

In my menu.js:

function showContent(showThis){ alert(showThis); }

Frank Doe
  • 192
  • 1
  • 3
  • 17

2 Answers2

0

Try like this:

echo "<img src='../images/home.png' onclick='showContent(\"$home\")' alt='Home' />";
kaczmen
  • 528
  • 4
  • 12
0

Try this. You are not interpolating the variable $home correctly into the JS.

echo "<img src=\"../images/home.png\" onclick=\"showContent('{$home}')\" alt=\"Home\" />";