Hello, I’ve spent the past hour search the web for possible solution, maybe I’m not using the right terms. I hope someone would be able to help me here. I have a form used inside the fancyBox iframe, after adding this ”if statement” below my submit button doesn’t work any more. However if I select more then 5 days I get the error alert (weird..). If I remove it the form submission works again.
if (VType == 'useRange'){
var splitName = vacDays.split(" - ");
var startDay = Date.parse(splitName[0].trim());
var endDay = Date.parse(splitName[1].trim());
var dayCount = (endDay - startDay) / (86400000);
if (dayCount > 4)
alert('The date range cannot exceed 5 consecutive days');
return false;
}
Here is the complete script, thank you in advance for you help!
$("#addVacButton").click(function(event){
event.preventDefault();
if (!$('#VacAddForm').valid())
return false;
var vacDays = $("#vacDays").val();
var VacHours = $("input[name='VacHours']:checked").length;
var VAC_UnschedTime = $("#VAC_UnschedTime").val();
var VAC_Unsched = $("#VAC_Unsched").val();
var VType = $("input[name='VTypeID']):checked").attr('id');
//check if date range exceed 5 days
if (VType == 'useRange'){
var splitName = vacDays.split(" - ");
var startDay = Date.parse(splitName[0].trim());
var endDay = Date.parse(splitName[1].trim());
var dayCount = (endDay - startDay) / (86400000);
if (dayCount > 4)
alert('The date range cannot exceed 5 consecutive days');
return false;
}
var data = $("#VacAddForm").serialize();
$.ajax({
url: "cfc/fms.cfc?method=insertVAC&returnformat=plain",
type: "POST",
data: data,
cache: false,
success: function (returnMessage) {
var returnMsg = jQuery.trim(returnMessage);
if (returnMsg.search(/Error/i) == '-1'){
alert('ok');
}
else{
alert('error');
}
}
});
return false;
});
Here is the link:
<a id="VacAddForm" href="forms/VacAddForm.cfm?id=#id#"> Add</a>