0

I have a html file:

<body>
  <?php 
    $rand1 = rand(0,10);
    $rand2 = rand(0,20);
  ?>

  <span id="client-registration-button">Registration</span>

  <script>var checksum = <?php echo $rand1+$rand2; ?>;</script>
  <script src="/main.js"></script>
</body>

And in main.js is:

$('#client-registration-button').click(function() {         
    alert(checksum);    
});

But the alert shows no value, just empty alert window. Why is there no value of global variable "checksum" displayed?

Incredible
  • 163
  • 11
  • Do you know the var is populated? Have you tested it in the HTML file first? – wmash Jun 29 '16 at 09:23
  • Possible duplicate of [How to send variables from one file to another in Javascript?](http://stackoverflow.com/questions/17309199/how-to-send-variables-from-one-file-to-another-in-javascript) – Destrif Jun 29 '16 at 09:28
  • Yes it is, here is an output: – Incredible Jun 29 '16 at 09:29

0 Answers0