Reputation: 126
i am calling a onchange function in my view. this field is picking date from calendar.
$('#IDContractDate').on('change', function (e) {
var GetThis = $(this).val();
var CoveredId = $('#ddlCoveredIndividual option:selected').attr('attribute2');
var relationshipId = $('#ddlCoveredIndividual option:selected').attr('code');
if (CoveredId !== 'undefined' && relationshipId !== "undefined") {
$.ajax({
type: "GET",
url: AppVirtualPath + "MemberDetails/GetEnrollmentDates?personId=" + CoveredId + "&benefitOptionId=" + $('#hdBenefitOptionId').val() + "&benefitId=" + $('#hdBenefitId').val() + "&relationShipId=" + relationshipId + "&contractDate=" + GetThis,
dataType: 'json',
success: function (data) {
$.each(data, function (key, value) {
if (key == "SystemEntryDate") {
$('#IDsystemEntryDate').val(value);
}
else if (key == "EntryDate") {
$('#IDEntryDate').val(value);
}
else if (key == "ADCSDate") {
$('#IDADCStartDate').val(value);
}
else if (key == "NDCSDate") {
$('#IDNDCStartDate').val(value);
}
});
},
error: function (xhr, textStatus, error) {
}
});
}
});
i am not able to understand why this function is calling three times. please help..
Upvotes: 0
Views: 398
Reputation: 41
Handle your change event with this unbind() function. Hope this will make help to you.
$("#IDContractDate").unbind().on('change',function(e) {
//Stuff
});
Upvotes: 1
Reputation: 715
Seems like handlers are getting attached multiple times. Unbind before hooking handler
$('#IDContractDate').unbind().on('change', function (e) {
});
Upvotes: 0