I have a field HrsBirthDate which should take input in format HH:MM (it can be 00:01, 01:19, 23:44, 19:34, 13:12).
So before submitting the form I need to check whether the value is in any of the above formats else throw an error message.
Now only I can check that the field is not empty.
This is my code:
$("body").on("click", "#WebGrid TBODY .Update", function () {
var row = $(this).closest("tr");
var employee = {};
employee.EmployeeID = row.find(".EmployeeId").find(".label").html();
employee.FirstName = row.find(".Name").find(".text").val();
employee.BirthDate = row.find(".DOB").find(".text").val();
employee.HrsBirthDate = row.find(".HrsBirthDate").find(".text").val();
if (employee.FirstName != '' && employee.BirthDate != '' && employee.HrsBirthDate != '') {
debugger;
$("td", row).each(function () {
if ($(this).find(".text").length > 0) {
var span = $(this).find(".label");
var input = $(this).find(".text");
span.html(input.val());
span.show();
input.hide();
}
});
row.find(".Edit").show();
row.find(".Cancel").hide();
$(this).hide();
$.ajax({
type: "POST",
url: "/Home/UpdateEmployee",
data: '{employee:' + JSON.stringify(employee) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json"
});
}
else {
alert("Please fill the details.");
return false;
}
});