Jackson
Jackson

Reputation: 264

How to Trigger an event on button click using jQuery

enter image description herei have an appointments plugin with an option to select particular days in a checkbox manner. I have added a custom validation for the field. Everything works fine. when we click next and reaches next step there is a back button. When we click on the back button it takes to the form without refreshing the data so MY CUSTOM VALIDATION on days is not working.

Here is my code,

jQuery(document).ready(function(){
  setTimeout(function(){
    jQuery(".ladda-button").attr('onclick','oniter()');
  },1750); 
 });

function oniter(){
  if (jQuery(".valid").find(".active").length>=1) {
    alert(123);
  } else {
    jQuery('.removeval').remove();
    jQuery(".validation_text").append("<font class='removeval'>Please Select a Day</font>");
  }
  jQuery(".valid").on ('change',function(){
    jQuery(".validation_text").remove();
  });       
}

This is how my validation works. I want to trigger the entire process when the back button is clicked to ensure the validation occurs . How to do this any idea?

Upvotes: 0

Views: 266

Answers (2)

Elvin Haci
Elvin Haci

Reputation: 3572

Your form's back button should have some class or ID, right? So just trigger same setTimeout when back button is clicked. f.e.

jQuery(document).on('click','.back-button',function(){
  setTimeout(function(){
    jQuery(".ladda-button").attr('onclick','oniter()');
  },1750);
});

Upvotes: 0

Yamu
Yamu

Reputation: 1662

jQuery(document).ready(function(){
  jQuery(document).on('click','.ladda-button',function(){
    oniter();
  });
});

function oniter(){
  if (jQuery(".valid").find(".active").length>=1) {
    alert(123);
  } else {
    jQuery('.removeval').remove();
    jQuery(".validation_text").append("<font class='removeval'>Please Select a Day</font>");
  }
  jQuery(".valid").on ('change',function(){
    jQuery(".validation_text").remove();
  });
}

Upvotes: 1

Related Questions