Hi i have a JavaScript validation code for a dynamically adding text boxes, it's showing alert when text boxes having empty values and not stopping there
$(document).on('click', '#med_submit', function () {
$(".medicine_name").each(function (i) {
var id = this.id;
var value = $("#" + id).val();
if (value.trim() == "") {
alert('Medicine name should not be empty');
return false;
}
});
$(".medicine_quantity").each(function (i) {
var id = this.id;
var value = $("#" + id).val();
if (value.trim() == "") {
alert('Quantity name should not be empty');
return false;
}
});
});
this is my script, in medicine_name each function there is any one medicine_name class textbox is empty then it shows alert message also it's going to the next medicine_quantity each function and show that alert too, here i am using return false after athe alert then how this happening, please help me
return falseinside theeach()exits the each early, not the parent function..eachwith a simpleforloop and replace thereturnwith abreakstatement then.