0

I'm getting an "Unterminated String Literal" error on all of these lines.

I am new to PHP so I'm a little lost.

Here's the code:

<a class="download" href="#" onclick="downloadSite('<?php echo $this->_tpl_vars['s']['url']; ?>
', <?php echo $this->_tpl_vars['s']['psid']; ?>
)"><img src="images/download.png" width="20" alt="Download" title="Download" /></a>

Thanks!

itsmeee
  • 1,587
  • 10
  • 12
novicePrgrmr
  • 17,409
  • 31
  • 80
  • 100
  • Is it PHP giving you the error or JavaScript? – nobody Sep 10 '11 at 19:28
  • @tsmeee has the most correct answer, likely. Since you're using PHP to echo values into a JavaScript method call, each argument needs to be escaped properly. Only numbers and variable references can be left "unquoted," and the second PHP value you echo isn't quoted. – Tieson T. Sep 10 '11 at 19:37

3 Answers3

1

I don't know PHP, but I observe that you're opening a string with ' right after downloadSite, and then also using ' inside that string, and don't seem to be closing it.

Tom Zych
  • 12,899
  • 9
  • 35
  • 52
1

You have to close first argument on same line

<a class="download" href="#" onclick="downloadSite('<?php echo $this->_tpl_vars['s']['url']; ?>'
genesis
  • 49,367
  • 20
  • 94
  • 122
1

Try adding json_encode before echoing each php variable. Also if $this->_tpl_vars['s']['psid'] is string, then you should also put it inside the quotes:

<a class="download" href="#" onclick="downloadSite('<?php echo json_encode($this->_tpl_vars['s']['url']); ?>', '<?php echo json_encode($this->_tpl_vars['s']['psid']); ?>'

)">

itsmeee
  • 1,587
  • 10
  • 12
  • it will encode a value to javascript notation. In your very case it will encode quotes that may appear in the string passed from PHP. Look at this question: http://stackoverflow.com/questions/168214/pass-a-php-string-to-a-javascript-variable-including-escaping-newlines – itsmeee Sep 10 '11 at 19:39