0

I have this script:

 . '<button type="button" '.($searchQuery['can_used'] == 1 ? 'onclick="var con=confirm(\'Let op: dit is de laatste keer dat u dit bestand kan downloaden, na deze keer word het bestand automatisch verwijderd. Weet u zeker dat u deze bestand wil download?\')"' : '').' class="btn btn-info">Download het bestand...</button>'
 . '<script type="text/javascript">alert(con)</script>';

Well, this is not working, I get an error what says 'con is not defined'. Because the var will not exist when I not click on the button. And I cannot click on the button because javascript will not continue on an error. How can I fix this? Is there other way to to this?

Thanks!

  • Have you tried defining the `con` variable so that an error isn't generated? Also, when asking JavaScript questions *don't* show us the server-side PHP; it's irrelevant. Show us the generated (relevant) HTML as-seen by the browser (under 'view source'). – David Thomas Nov 16 '13 at 15:06
  • This maybe what you want: [access php varaible in javascript](http://stackoverflow.com/questions/4287357/access-php-variable-in-javascript) – gongzhitaao Nov 16 '13 at 15:11
  • No, thats not what I needed. But its fixed now. See my answer. – user2897922 Nov 16 '13 at 15:16

1 Answers1

0

Thanks to David Thomas.

Fixed by creating the var before the confirm.

Uw bestand is gevonden! <br />U kunt dit bestand nog <b><u>1</b></u> keer downloaden via deze website. U kunt dit bestand tot en met <b><u>19-01-2038 04:14:07</b></u> downloaden. <br />Bestand naam: <b><u>download.rar</b></u> <br />Bestand grootte: <b><u>87.82 mb</b></u> <br /><br /><script>var con = false;</script><button type="button" onclick="con=confirm('Let op: dit is de laatste keer dat u dit bestand kan downloaden, na deze keer word het bestand automatisch verwijderd. Weet u zeker dat u dit bestand wilt downloaden?'), alert(con)" class="btn btn-info">Download het bestand...</button>

Thank you David.