I am facing one issue. The return statement is not working as expected using Javascript/Jquery. I am explaining my code below.
$.each(resultArr,function(i,data){
console.log('dt',data);
var rule = $("#sub"+i).val();
if (rule == '') {
var subject=data.sub_name;
toastr.error('Attendance for '+ subject +' can not be blank');
return false;
}else if (parseInt(rule) > 100) {
var subject=data.sub_name;
toastr.error('Attendance for '+ subject +' can not be more than 100');
return false;
}else{
data.attendance=rule;
if (data.id == '') {
flag=0;
}else{
flag=1;
}
}
})
Here I need if else if
is true it should return after displaying the error message. but in my case its showing the error message and also the else
part is executing and value is assigning to flag variable. Here I need once error message will display it should return from there.