I am using below jQuery function to validate all fields inside a div. My problem is it always return false even I fill all the fields.
function validate(id) {
//:text, :checkbox, select, textarea
var isFormValid = true;
var div = $(id);
$(div).find(":text, select").each(function () {
if (this.value == "" && !$(this).hasClass("no-req")) {
$(this).addClass("required");
isFormValid = false;
$(this).focus();
}
else {
$(this).removeClass("required");
}
});
if (!isFormValid) {
alert("Please fill all the higlighted fields!");
}
return isFormValid;
}
On Asp.net button client click I am using this code
<asp:Button ID="btnSave" runat="server" Text="Save" class="btn btn-success" OnClientClick="javascript: return validate('#tdAdd');" OnClick="btnSave_Click" />