验证显示在开始时间和结束时间,但它没有显示在中断开始和中断结束

时间:2015-07-16 06:29:20

标签: javascript

请参阅以下代码

function chk_submit_all()
{
  var frm = document.add_advert;
  if (frm.avl_after.value.search(/\S/) == '-1')
  {
     document.getElementById('error_avl_after').innerHTML = 'Please choose date, you are available on or after';
     frm.avl_after.focus();
     return false;
  }
  else
  {
     document.getElementById('error_avl_after').innerHTML = '';
  }
  var count_all = 0;
  $('input:checkbox.choose_days').each(function (index, element )
  {
     if (this.checked == true)
     {
         var strt_time = $(this).val();
         var strt_val = $('#start_time_'+strt_time).val();
         var startTime = new Date().setHours(GetHours(strt_val), GetMinutes(strt_val), 0);

         if ($('#start_time_'+strt_time).val() == '')
         {
             document.getElementById('error_avl_day_time').innerHTML = 'Please choose start time';
             breakOut = true;
           //alert('Please choose start time');
         }
         else
         {
                var end_time = $('#end_time_'+strt_time).val();
                var endTime = new Date(startTime)
                endTime = endTime.setHours(GetHours(end_time), GetMinutes(end_time), 0);
                if (endTime <= startTime)
                {
                   document.getElementById('error_avl_day_time').innerHTML = 'end time should be higher than start time';
                  //  alert('end time should be higher than start time');
                     breakOut = true;

                }
                else
                {

其他部分无效 请看看我做错了什么。 没有进入其他部分 验证显示在开始时间和结束时间,但它没有显示在中断开始和中断结束

 //alert ('hii'); die;
                    // alert($('#radio-'+strt_time+'-brk').val()); die;
                    if ($('#radio-'+strt_time+'-brk').checked == true)
                    {
                        alert ('hii'); exit;
                         var brk_strt_time_val = $('#break_time_start_'+strt_time).val();
                         var brk_strt_time = new Date().setHours(GetHours(brk_strt_time_val), GetMinutes(brk_strt_time_val), 0);
                         if ((brk_strt_time > strt_time) && (brk_strt_time < end_time))
                         {
                            //alert (hiii);die;
                            var brk_end_time_val = $('#break_time_end_'+strt_time).val();
                            var brk_end_time = new Date().setHours(GetHours(brk_end_time_val), GetMinutes(brk_end_time_val), 0);
                            if (brk_strt_time >= brk_end_time)
                            {
                                //alert('break end time should be higher than break start time'); die;
                                document.getElementById('error_avl_day_time').innerHTML = 'break end time should be higher than break start time';
                                //alert('break end time should be higher than break start time');
                                breakOut = true;
                            }
                            else
                            {
                                count_all++;
                            }
                        }
                    }
                    else
                    {
                        count_all++;
                    }
               }

        }
     }

   });

  if (count_all == 0)
  {
    document.getElementById('error_avl_day_time').innerHTML = 'Please choose day with time';
    return false;
  }
  else
  {
     if(breakOut)
     {
        breakOut = false;
        return false;
     }
     else
     {
        document.getElementById('error_avl_day_time').innerHTML = '';
     }

  }

}

1 个答案:

答案 0 :(得分:0)

这是Coders的答案

function chk_submit_all()
{
   var frm = document.add_advert;
   if (frm.avl_after.value.search(/\S/) == '-1')
   {
      document.getElementById('error_avl_after').innerHTML = 'Please choose date, you are available on or after';         
      frm.avl_after.focus();
      return false;
   }
   else
   {  
      document.getElementById('error_avl_after').innerHTML = '';
   }
   var flag=0;
   var count=0;
   var start_time = document.getElementsByName('days_val[]');
   var len = start_time.length;
   for(i=0;i<len;i++){
      if(start_time[i].checked){
         var strt_time = start_time[i].value;
         var strt_val = $('#start_time_'+strt_time).val();
         var end_val = $('#end_time_'+strt_time).val();
         if (strt_val=='') {
            document.getElementById('error_avl_day_time').innerHTML = 'Please choose a Start time';
            flag=1;
            break;
         }
         else
         {
            if (strt_val>=end_val) {
               document.getElementById('error_avl_day_time').innerHTML = 'End Time Must be greater than Start Time';
               flag=1;
               break;
            }
            else{
               if ($('#radio-'+strt_time+'-brk').is(':checked'))
               {
                  var brk_strt_time_val = $('#break_time_start_'+strt_time).val();
                  var brk_end_time_val = $('#break_time_end_'+strt_time).val();
                  if ((brk_strt_time_val=='') || (brk_end_time_val=='')) {
                     document.getElementById('error_avl_day_time').innerHTML = 'Please Choose Valid Break Time';
                     flag=1;
                     break;
                  }
                  else
                  {
                     if ((brk_strt_time_val=='00:00') || (brk_end_time_val=='00:00')) {
                        document.getElementById('error_avl_day_time').innerHTML = 'Please Choose Valid Break Start/End Time';
                        flag=1;
                        break;
                     }
                     else{
                        if (((brk_strt_time_val <= strt_val) || (brk_strt_time_val >= end_val))|| ((brk_end_time_val <= strt_val) || (brk_end_time_val >= end_val))) {
                           document.getElementById('error_avl_day_time').innerHTML = 'Break Start/End Must be within Start time and End Time';
                           flag=1;
                           break;
                        }
                        else
                        {
                           if (brk_strt_time_val>=brk_end_time_val) {
                              document.getElementById('error_avl_day_time').innerHTML = 'Break End time Must be greater than Break Start Time';
                              flag=1;
                              break;
                           }
                        }
                     }
                  }
               }
            }
         }
         count++;
      }
   }
   if (count==0 && flag==0) {
      document.getElementById('error_avl_day_time').innerHTML = 'Pleas Choose Atleast One Time Slot';
      return false;
   }
   else{
      if (flag==1) {
         return false;
      }
      else
      {
         document.getElementById('error_avl_day_time').innerHTML = '';
      }
   }
}