Set var value from another javascript file using jQuery

I have two JavaScript files:

  • Main.js
  • Pmt.js

I also use a thick box (Ajax call)

in Main.js

$(document).ready(function() { var cnt=0; $("#btnPmt").click(function(){ cnt=cnt+1; tb_show('Void Transaction','pmt.jsp?height=310&width=400', null); }); }); 

The Pmt.js file is included in pmt.jsp as

 <script src="js/Pmt.js" type="text/javascript"></script> 

in Pmt.js

  $("#btnPmtClose").click(function(){ cnt=0; parent.tb_remove(); }); 

How can we reset the var cnt value in Pmt.js , which is decal in Main.js ? The above does not work, when I close the thick box, I find the increased value, not the zero set when closing, even the Ajax call.

+4
source share
1 answer

in Main.js do cnt as a global var, moving it outside of any function:

 var cnt=0; $(document).ready(function() { ... }) 
+6
source

All Articles