2010-12-15 3 views
1

Мой код вызывает ie7, чтобы выбросить эту ошибку. 'this.0.form' является нулевым или не является объектом . Кнопка, которая запускает форму для отправки, когда она нажимается , когда это происходит, форма проверяется, но плагин проверки. В других браузерах это работает безупречно. В ie7 происходит сбой и ожоги, выкидывающие указанную выше ошибку.jquery validation 'this.0.form' является нулевым или нет объектом

$(document).ready(function(){ 
    //form rotate to next section 
    window.section = 1; 
    function secnext() 
    { 
     var current; 
     var next; 
     var valid; 
     current = window.section;   
     //on next validate fields 
     //if not valid submit form to return errors and return 0 
     switch(current) 
     { 
      case 1: 
      valid = section1(); 
      break; 
      case 2: 
      valid = section2(); 
      break; 
      case 3: 
      valid = section3(); 
      break; 
      case 4: 
      valid = section4(); 
     } 
     if(valid == false) return 0; 

     //if(current == 4) next == 0; 
     next = current+1; 
     if(current == 1) $('#previous').parent().show('slow'); 
     //hide current 
     $('#section'+current).hide('slide',500,function() 
     { 
      $('#section'+next).show('slide',500);}); 
      //display next 

      //setTimeout(function() { $('#section'+next).slideToggle('slow');}, 300); 
      if(next == 4) 
      { 
       $('#next').parent().hide('slow'); 
       $('#sendbutton').parent().parent().show('slow'); 
      } 
      window.section = next; 
     } 
     $('#next').click(function() 
     { 
      //$dialog.dialog("open");   
      secnext(); 
      //setTimeout(function() { $dialog.dialog("close"); }, 1500);  

     }); 
     // hide section by section if all fields are valid and focus is in different section 
     function section1() 
     { 
      if($('input#fname').valid() && 
      $('input#lname').valid() && 
      $('input#email').valid() && 
      $('input#homephone').valid() && 
      $('select#ismilitary').valid()) 
      { 
       return true; 
      } else { 
       $('form#creditapp').submit(); 
       return false; 
      } 
     } 
     function section2() 
     { 
      if($('input#address').valid() && 
      $('input#city').valid() && 
      $('input#state').valid() && 
      $('input#zip').valid() && 
      $('select#dob_month').valid() && 
      $('select#dob_day').valid() && 
      $('select#dob_year').valid() && 
      $('input#ssn').valid() && 
      $('input#dlnum').valid() && 
      $('input#dlst').valid()) 
      { 
       return true; 
      } else { 
       $('form#creditapp').submit(); 
       return false; 
      }  
    } 
    function section3() 
    { 
      if($('input#employer').valid() && $('input#workphone').valid() && $('select#employed_year').valid() && $('select#employed_month').valid() 
      && $('select#paymethod').valid() && $('select#incomesrc').valid() && $('input#paychkamount').valid() && $('select#payfreq').valid() 
      && $('input#nextpayday1').valid() && $('input#nextpayday2').valid()) 
      { 
       return true; 
      } else { 
       $('form#creditapp').submit(); 
       return false; 
      } 
    } 
    function section4() 
    { 
      if($('input#bankname').valid() && $('select#acctype').valid() && $('input#routingnum').valid() && $('input#accnum').valid()) 
      { 
       return true; 
      } else { 
       $('form#creditapp').submit(); 
       return false; 
      } 
    } 
    /*section1(); 
    section2(); 
    section3(); 
    section4();*/ 
    /** 
    * assign click handler to button 
    * on button click reassign focus event to section and hide button 
    **/ 
    /*$('.button').click(function(index){ 
     switch($(this).parent().parent().attr('id')) 
     { 
      case 'button1': 
       $('#button1').slideToggle('slow'); 
       $('#section1').slideToggle('slow'); 
       section1(); 
       break; 
      case 'button2': 
       $('#button2').slideToggle('slow'); 
       $('#section2').slideToggle('slow'); 
       section2(); 
       break; 
      case 'button3': 
       $('#button3').slideToggle('slow'); 
       $('#section3').slideToggle('slow'); 
       section3(); 
       break; 
      case 'button4': 
       $('#button4').slideToggle('slow'); 
       $('#section4').slideToggle('slow'); 
       section4(); 
       break; 
     } 
    });*/ 

    function hidesections() 
    { 
     /*if($('input#fname').valid() && $('input#lname').valid() && $('input#email').valid() && $('input#homephone').valid() && $('select#ismilitary').valid()) 
     { 
      $('#section1').hide('slow'); 
     } 
     if($('input#address').valid() && $('input#city').valid() && $('input#state').valid() && $('input#zip').valid() && $('[name="bday"]').valid() 
     && $('input#ssn').valid() && $('input#dlnum').valid() && $('input#dlst').valid()) 
     { 
      $('#section2').hide('slow'); 
     } 
     if($('input#employer').valid() && $('input#workphone').valid() && $('select#employed_years').valid() && $('select#employed_months').valid() 
     && $('select#paymethod').valid() && $('select#incomesrc').valid() && $('input#paychkamount').valid() && $('select#payfreq').valid() 
     && $('input#nextpayday1').valid() && $('input#nextpayday2').valid()) 
     { 
      $('#section3').hide('slow'); 
     } 
     if($('input#bankname').valid() && $('select#acctype').valid() && $('input#routingnum').valid() && $('input#accnum').valid()) 
     { 
      $('#section4').hide('slow'); 
     }*/ 
    } 
    //save whole form 
    function saveform() 
    { 
     var data = ''; 
     $('input').each(function(index) { 
      data += $(this).attr('name')+'='+$(this).val()+'&'; 
     }); 
     $('select').each(function(index) { 
      if($(this).attr('name') != 'employed_years' && $(this).attr('name') != 'dob_month' && $(this).attr('name') != 'dob_day') 
      { 
       switch($(this).attr('name')) 
       { 
        case 'employed_months': 
         value = $('select#employed_years').val() * 12 
+ $('select#employed_months').val(); 
         data += 'emplength='+value+'&'; 
         break; 
        case 'dob_year': 
         value = $('select#dob_month').val()+'/'+$('select#dob_day').val()+'/'+$('select#dob_year').val(); 
         data += 'bday='+value+'&'; 
         break; 
        default: 
         data += $(this).attr('name')+'='+$(this).val()+'&'; 
       } 
      } 
     }); 
     $.ajax({ 
      type: "POST", 
      url: "submit.php?type=form", 
      data: data, 
      success: function(msg){ 
      //alert('Your Application has been sent'); 
      window.location = "http://www.galleryhomestore.com/success"; 
      } 
     }); 
    }  //validation $('#creditapp').validate({ 
     /*groups: { 
      bday: "dob_month dob_day dob_year" 
     }, 
     errorPlacement: function(error, element) { 
      if (element.attr("name") == "dob_month" 
        || element.attr("name") == "dob_day" || element.attr("name") == "dob_year") 
       error.insertAfter("#dob_year"); 
      else 
       error.insertAfter(element); 
     },*/ 
     submitHandler: function() { 
      //alert('submitted'); 
      /* 
      bday and years employed 

      */ 
      //if($('#dob_day').val() != 'day' && $('#dob_month').val() != 'month' && $('#dob_year').val() != 'year' && $('#employed_month').val() != 'month' && $('#employed_year').val() != 'year') 
      //{ 
       $('div#form').slideToggle('slow'); 
       $('#sending').slideToggle('slow'); 
       saveform(); 
      //}   
     } 
    }); 

ответ

0

То же самое, что у меня есть, кроме моего, почти невозможно найти.

Ваша проблема, если вы еще не нашли ее, вызвана прокомментированной запятой перед обработчиком отправки.

},*/ 
     submitHandler: function() { 
+0

О, это хуже, чем это ... `` `над комментарием закрывает эту функцию, а` submitHandler` плавает в воздухе; это не часть `ajax()`. Этот способ написания JS для меня какой-то странный, почему все функции объявлены внутри `ready ({...})`? – Liz 2011-04-04 09:32:46

Смежные вопросы