How to prevent submission of form : <p>I have a form with ajax calls:</p>

<pre><code>&lt;form method="post" action="?slt=Sbmt" onsubmit="return validateForm()" id="reportform" enctype="multipart/form-data"&gt;

&lt;div id="evaluation1"&gt;
&lt;h2&gt;Rate Technical Skills&lt;/h2&gt;
    &lt;table class="quartz-table" id="techskills_table"&gt;   
        &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;Driver&lt;/th&gt;
              &lt;th&gt;Sub-Driver&lt;/th&gt;
              &lt;th class="sorter-false"&gt;Skill&lt;/th&gt;  
              &lt;th class="sorter-false"&gt;Marks&lt;/th&gt;  
            &lt;/tr&gt;
      &lt;/thead&gt;
    &lt;?php
    foreach( $subdriver as $sbdriver =&gt; $sbd ) 
    {
        $skillsResult = getTechSkills($yes, $role, $sbd);
        $countTech = 0;

        while($row = mysqli_fetch_array($skillsResult))
        {    
            $id = $row['id'];
            $driver = $row['driver'];
            $subdriver = $row['subdriver'];
            $dep = $row['department'];
            $skill = $row['skills'];
            $vrgood = $row['4'];
            $good = $row['3'];
            $middle = $row['2'];
            $low = $row['1'];
    ?&gt;
        &lt;tbody&gt;
            &lt;tr class="full_qst"&gt;
                &lt;td&gt;&lt;?php echo $driver; ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $subdriver; ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $skill; ?&gt;&lt;/td&gt;
                &lt;td&gt; &lt;img alt="" src="imagesAssessment/check.png" class="check"&gt;
                    &lt;div class="mrk"&gt;
                        &lt;label class="choice" for="q1_a" &gt;&lt;input class="q" name="q1_a[]" type="checkbox" value="&lt;?php echo $low ?&gt;"/&gt;1&lt;/label&gt;
                        &lt;label class="choice" for="q1_b" &gt;&lt;input class="q" name="q1_a[]" type="checkbox" value="&lt;?php echo $middle ?&gt;"/&gt;2&lt;/label&gt;
                        &lt;label class="choice" for="q1_c" &gt;&lt;input class="q" name="q1_a[]" type="checkbox" value="&lt;?php echo $good ?&gt;"/&gt;3&lt;/label&gt;
                        &lt;label class="choice" for="q1_d" &gt;&lt;input class="q" name="q1_a[]" type="checkbox" value="&lt;?php echo $vrgood ?&gt;"/&gt;4&lt;/label&gt;
                    &lt;/div&gt;   
                    &lt;input id="q" name="q[]" type="hidden" value="&lt;?php echo $id; ?&gt;" /&gt; 
                    &lt;input name="dep[]" type="hidden" value="&lt;?php echo $dep; ?&gt;" /&gt;    
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/tbody&gt;
    &lt;?php
    $countTech++;
        }
    }    
    ?&gt;            
    &lt;/table&gt;
&lt;button type='button' class='ev_quest2' data-id3="&lt;?php echo $yes.'|'.$role.'|'.$quarter.'|'.$username.'|'.$staffid; ?&gt;"&gt;Performance Skills&lt;/button&gt;
&lt;/div&gt;
&lt;div id="evaluation3"&gt;&lt;/div&gt;

&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;
&lt;/form&gt;  
</code></pre>

<p>I call ajax to display in evaluation3 . Here is code to display data:</p>

<pre><code>$(document).on('click', '.ev_quest3', function(){
    var row_number2 = "&lt;?php echo $countPerf; ?&gt;"; 
    var checked_number2 = $("#evaluation2 :checkbox:checked").length;
    if(row_number2 == checked_number2){
        var evaluation3 = $(this).data("id3");
        $.ajax({
            url: "comAssessment/scoreboard_evaluation_closed.php",
            method: "POST",
            data: {evaluation3: evaluation3},
            dataType:"text",
            success: function (data) {
                $('.quest3').hide();
                $("#evaluation3").hide().html(data).show("slide", { direction: "up" }, 1500);
            }
        });
    }else{ alert('Please Rate all Performance Skills first!'); }
});
</code></pre>

<p>So I check sum of checked checkboxes and sum of checkboxes from the database. If its not equal then system wont upload data. In the end I want to check if all checkboxes of id evaluation3 are checked. If yes then submit the form if not just give alert and stay on the page. </p>

<p>And here is scoreboard_evaluation_closed.php:</p>

<pre><code>&lt;table id="closedquest_table" class="quartz-table"&gt;   
    &lt;thead&gt;
        &lt;tr&gt;
          &lt;th class="sorter-false"&gt;Skill&lt;/th&gt;  
          &lt;th class="sorter-false"&gt;Marks&lt;/th&gt;  
        &lt;/tr&gt;
    &lt;/thead&gt;    
&lt;?php   
    while($row = mysqli_fetch_array($closedResult))
    {
        $id = $row['id'];
        $dep = $row['department'];
        $skill = $row['question'];
        $vrgood = $row['4'];
        $good = $row['3'];
        $middle = $row['2'];
        $low = $row['1'];
?&gt;
    &lt;tbody&gt;
    &lt;tr class="full_qst"&gt;
        &lt;td&gt;&lt;?php echo $skill; ?&gt;&lt;/td&gt;
        &lt;td&gt; &lt;img alt="" src="imagesAssessment/check.png" class="check"&gt;
            &lt;div class="mrk"&gt;
                &lt;label class="choice" for="q1_a" &gt;&lt;input class="q" name="q1_a[]" type="checkbox" value="&lt;?php echo $low ?&gt;"/&gt;1&lt;/label&gt;
                &lt;label class="choice" for="q1_a" &gt;&lt;input class="q" name="q1_a[]" type="checkbox" value="&lt;?php echo $middle ?&gt;"/&gt;2&lt;/label&gt;
                &lt;label class="choice" for="q1_a" &gt;&lt;input class="q" name="q1_a[]" type="checkbox" value="&lt;?php echo $good ?&gt;"/&gt;3&lt;/label&gt;
                &lt;label class="choice" for="q1_a" &gt;&lt;input class="q" name="q1_a[]" type="checkbox" value="&lt;?php echo $vrgood ?&gt;"/&gt;4&lt;/label&gt;
            &lt;/div&gt;   
            &lt;input id="q" name="q[]" type="hidden" value="&lt;?php echo $id; ?&gt;" /&gt; 
            &lt;input name="dep[]" type="hidden" value="&lt;?php echo $dep; ?&gt;" /&gt;    
        &lt;/td&gt;      
    &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;?php
    $countClosed++;
    }
?&gt;
&lt;/table&gt;
</code></pre>

<p>And function to prevent submission if not all checkboxes are checked:</p>

<pre><code>$(function () {
    $('form').on('submit', function (e) {
        var row_number3 = "&lt;?php echo $countClosed; ?&gt;"; 
        var checked_number3 = $("#evaluation3 :checkbox:checked").length;    

        if(row_number3 != checked_number3){
            e.preventDefault();
            alert(/*'Please Rate all Closed Questions'*/ row_number3+' a / b '+checked_number3);
        }  
    });
});
</code></pre>

<p>So the problem is it gets me alert message but it also submit the form after giving first alert message. How can I prevent form from submission if not all checkboxes are checked?</p>
