2012-02-03 185 views
0
$('form#injuryReportSubmit').submit(function(){    
if(($('form#injuryReportSubmit textarea.description').val().length <=0) || ($('form#injuryReportSubmit select.part').val()== "choose one...") ||($('form#injuryReportSubmit select.type').val() == "choose one...") || ($('form#injuryReportSubmit select.weather').val()=="choose one...")); 
      { 
       $('div#errorMessage').show(); 
       return false; 
      }   
}); 

上面的代碼用於在提交表單之前驗證表單。問題是即使所有的測試都是錯誤的,表單也不會提交。有人可以幫忙嗎? 的形式是在一個jsp,看起來像表單不在Jquery驗證後提交

<form id ="injuryReportSubmit" method ="post" action="injuryReportingPage.html" > 
     <p class ="first" >Date Of Injury</p> 
     <p class ="second">Date Reported to Manager</p> 
     <input type="text" id="dateOfInjury" name="dateOfInjury">  
     <input type="text" id="dateReported" name ="dateReported"> 
     <p class ="weather">Weather</p> 
     <p class ="injuryType">Injury Type</p> 
     <p class ="bodyPart">Body Part</p> 
     <p class ="time">Time Injury Occurred</p> 
     <p class ="description">Description</p> 
     <select class ="weather" name="weather"> 
     <%if(InjuryReportController.getWeatherList() != null){ %> 
     <% for(Weather weather : InjuryReportController.getWeatherList()){%> 
     <option><%= weather.getWeatherCondition() %></option> 
     <%} }%> 
     <option >choose one...</option> 
     </select> 

     <select class ="type" name="injuryType">   
     <%if(InjuryReportController.getInjuryTypeList() != null){ %>  
     <% for(InjuryType injuryType : InjuryReportController.getInjuryTypeList()){%> 
     <option><%= injuryType.getInjuryTypeName() %></option> 
     <%} }%> 
     <option>choose one...</option> 
     </select> 

     <select class ="part" name="bodyPart">  
     <%if(InjuryReportController.getBodyPartList() != null){ %> 
     <% for(BodyPart bodyPart : InjuryReportController.getBodyPartList()){%> 
     <option><%= bodyPart.getBodyPartName() %></option> 
     <%} }%> 
     <option >choose one...</option> 
     </select> 

     <input type="text" id="timeP" name ="timeOfInjury" value="01:00 AM"> 
     <textarea class ="description" rows="120" cols="670" name="description"></textarea> 

     <input id ="report" value="Submit Report" type ="submit"> 

     </form> 

回答

1

從代碼中的第5行的末尾刪除分號。

目前你所得到的是這樣的:

if (/*your conditions*/);  // <- note the semicolon 
{ 
    ... 
    return false; 
} 

這意味着,與大括號塊不與if聲明有關,因此將執行每一次。每次取消每次提交時顯然返回false

+0

你是絕對正確的,我不知道我怎麼沒有看到...非常感謝 – Cerebro 2012-02-03 02:14:02