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?

3
  • Do you know the var is populated? Have you tested it in the HTML file first? Commented Jun 29, 2016 at 9:23
  • Possible duplicate of How to send variables from one file to another in Javascript? Commented Jun 29, 2016 at 9:28
  • Yes it is, here is an output: <script>var checksum = 22;</script> Commented Jun 29, 2016 at 9:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.