Question

I have a two JavaScript files:

  1. Main.js
  2. Pmt.js

I'm also using 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 we can reset the value of var cnt in Pmt.js that decalred in Main.js? The above is not working, when I close the thickbox, I find the incremented value, not zero that set on close, even Ajax call.

Was it helpful?

Solution

in Main.js make cnt as global var by moving it outside any function :

var cnt=0;
$(document).ready(function() {
    ...
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top