$('#ms_cats_meta_eduyear, #ms_cats_meta_semester, #ms_cats_meta_subject').change(function () {
$('#publish').removeClass('button-primary-disabled');
$('#save-post').removeClass('button-disabled');
$('input#publish').click( function () {
var eduyear_val = $("#ms_cats_meta_eduyear").val();
var semester_val = $('#ms_cats_meta_semester').val();
var subject_val = $("#ms_cats_meta_subject").val();
if (eduyear_val == -1 || semester_val == -1 || subject_val == -1){
var msg= "من فضلك تأكد من ادخال جميع حقول اختيار التصنيف.";
$('#ajax-loading').hide();
alert(msg);
return false;
}else{
$('#publish').removeClass('button-primary-disabled');
$('#save-post').removeClass('button-disabled');
return true;
}
});
});
I’m using the function to produce an alert if the user tries to submit the form with the value of a three select boxes is -1. The Alert appears more than one time increasingle on making changes to the select box value, any idea what’s wrong ?
You create a click event inside the change event, that is, every time the change event is triggered a new click event is created (in addition to those already created before).
Just move the click event outside the change event.