Форма не отправляется после проверки Jquery - PullRequest
0 голосов
/ 03 февраля 2012
$('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 и выглядит как

<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 Ответ

1 голос
/ 03 февраля 2012

Удалите точку с запятой в конце строки 5 вашего кода.

В настоящее время то, что у вас есть, выглядит так:

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

Это означает, что блок с фигурными скобками не связан с оператором if и будет выполняться каждый раз. Очевидно, что возврат false каждый раз отменяет каждую отправку.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...