jquery prevent function running more than once -


mysepsistimer (a simple countdown timer) initiates once option select criteria (sepsis-six-sirs) reached. but, if user clicks on select option after starting timer function, duplicate clock runs. how can prevent mysepsistimer function running more once, or reset if user clicks (or unselects) 1 of same (sepsis-six-sirs) options.

$('#sepsis-six-sirs input[type=checkbox]').change(function(){ recalculatethisissepsis(); });  function recalculatethisissepsis(){ var sum = 0; $("#sepsis-six-sirs input[type=checkbox]:checked").each(function(){     sum+=parseint($(this).val()); });  if (sum > 1) {     mysepsistimer(); }} 

try utilizing $.callbacks("once")

var callbacks = $.callbacks("once");  callbacks.add(mysepsistimer);  $('#sepsis-six-sirs input[type=checkbox]').change(function() {   recalculatethisissepsis(); });  function recalculatethisissepsis(){   var sum = 0;   $("#sepsis-six-sirs input[type=checkbox]:checked").each(function() {     sum+=parseint($(this).val());   });    if (sum > 1) {     callbacks.fire();   } } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -