简体   繁体   中英

Form submit doesn't work

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> 

You need to provide proper block for the if statement:

if (dayCount > 4) {           
        alert('The selected days can\'t exceed 5 days');
        return false;
}

On the 10th line, you should use // instead of \\, hence your comment is wrong. Change it to backlash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM