Naughty Ninja Naughty Ninja - 1 year ago 39
Javascript Question

AJAX call passing always true for checkbox data

Ajax call is always passing true for isHalfDay checkbox, every other value that is being passed is correct apart from this one. What might be the reason?

UpdateDays: function () {
url: $("#numberOfDays").data("url"),
data: {
startDate: $("input[name=StartDate]").val(),
endDate: $("input[name=EndDate]").val(),
employeeId: $("#holiday-editor").data("employee"),
isHalfDay: $("input[name=HalfDay]").val()
method: "POST"
}).success(function (response) {


It's because the checkbox always has a value. If you want to know if it's checked or not use prop('checked'), like this:

isHalfDay: $("input[name=HalfDay]").prop('checked')

Also note that there is no success() method on the promise returned from the $.ajax call - I think you mean done() instead.