jquery function stops adding numbers up in php
<p>I have a piece of code below where it determines which assessment the user is in and the assessment number the user is currently on:</p>

<pre><code>   &lt;?php echo $sessionMinus ?&gt; OF &lt;?php echo $_SESSION['initial_count'] ?&gt;
</code></pre>

<p>So on the browser this could read for example:</p>

<pre><code>1 OF 4
</code></pre>

<p>Now below I have a submit button:</p>

<pre><code>&lt;input id="addQuestionBtn" name="addQuestion" type="button" value="Add Question" onClick="insertQuestion(this.form)" /&gt;
</code></pre>

<p>Now if the user clicks on the button, it will show a confirmation box and if the user clicks OK, for the confirmation, then it will submit the page and what is suppose to happen is that it adds a number to the assessment to indicate that the user is on the next assessment.</p>

<p>SO FOR EXAMPLE:</p>

<p>If it says this on the page:</p>

<pre><code>1 OF 4
</code></pre>

<p>If the user submits the page and confirms, then it should now say this:</p>

<pre><code>2 OF 4
</code></pre>

<p>This is because the user is on the next assessment now.</p>

<p>But the problem is that it is not adding the number at all when the user submits the page. It just stays at '1' and doesn't add up. So instead of doing the above it is doing the below:</p>

<p>If it says this on the page:</p>

<pre><code>1 OF 4
</code></pre>

<p>If the user submits the page and confirms, then it still says:</p>

<pre><code>1 OF 4
</code></pre>

<p>This is obviously incorrect.</p>

<p>I have tested my code and what I have found is that if there is that the jquery <code>validation()</code> is causing the number to not add up and stay at '1'. But my question is that how come this jquery function is causing this to happen?</p>

<p>Below is the jquery <code>validation()</code> function:</p>

<pre><code>function validation() {

    var _qid = "";
    var _msg = "";

    var alertValidation = "";
    // Note, this is just so it's declared...
    $("tr.optionAndAnswer").each(function() {

        });


    if (alertValidation != "") {
        alert(_msg + alertValidation);
        return false;
    }

    return true;

}
</code></pre>

<p>Below is relevant code so you know what the code is:</p>

<pre><code>    &lt;?php

    session_start();


    if(isset($_POST['sessionNum'])){
                //Declare my counter for the first time

                $_SESSION['initial_count'] = $_POST['sessionNum'];
                $_SESSION['sessionNum'] = intval($_POST['sessionNum']);
                $_SESSION['sessionCount'] = 1;

        }

    elseif (isset($_POST['submitDetails']) &amp;&amp; $_SESSION['sessionCount'] &lt; $_SESSION['sessionNum']) {
        $_SESSION['sessionCount']++;
    }


    $sessionMinus =  $_SESSION['sessionCount'];

    if ($sessionMinus == $_SESSION['initial_count']){ 

        $action = 'create_session2.php'; 

    }elseif($sessionMinus != $_SESSION['initial_count']){ 

        $action = $_SERVER['PHP_SELF']; 

    }

    ?&gt;

    &lt;script type="text/javascript"&gt;


    function validation() {

        var _qid = "";
        var _msg = "";

        var alertValidation = "";
        // Note, this is just so it's declared...
        $("tr.optionAndAnswer").each(function() {

            });


        if (alertValidation != "") {
            alert(_msg + alertValidation);
            return false;
        }

        return true;

    }




                 function showConfirm(){

             var confirmMsg=confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Session." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" );

             if (confirmMsg==true)
             {
             submitform();   
         }
    }

             function submitform()
    {
        var fieldvalue = $("#QandA").val();
        $.post("insertQuestion.php", $("#QandA").serialize() ,function(data){
            var QandAO = document.getElementById("QandA");
            QandAO.submit();
        });  
        alert("Your Details for this Session has been submitted"); 
    }




    &lt;/script&gt;

    &lt;/head&gt;

    &lt;body&gt;

    &lt;form id="QandA" action="&lt;?php echo htmlentities($action); ?&gt;" method="post"&gt;

    &lt;h1&gt;&lt;?php echo $sessionMinus ?&gt; OF &lt;?php echo $_SESSION['initial_count'] ?&gt;&lt;/h1&gt;

    &lt;div id="detailsBlock"&gt;


&lt;table id="questionBtn" align="center"&gt;
&lt;tr&gt;
&lt;th&gt;
&lt;input id="addQuestionBtn" name="addQuestion" type="button" value="Add Question" onClick="insertQuestion(this.form)" /&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;/div&gt;
&lt;hr/&gt;

&lt;div id="details"&gt;
&lt;table id="qandatbl" align="center"&gt;
&lt;thead&gt;
&lt;tr&gt;
    &lt;th class="question"&gt;Question&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;

    &lt;p&gt;&lt;input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="myClickHandler(); return false;" /&gt;&lt;/p&gt;

    &lt;/form&gt;

             &lt;script type="text/javascript"&gt;

    function myClickHandler(){
         if(validation()){
                    showConfirm();
         }
    }

    &lt;/script&gt;
</code></pre>

<p>UPDATE:</p>

<p>Below is the code of in the insertQuestion() function:</p>

<pre><code>function insertQuestion(form) {   


    var $tbody = $('#qandatbl &gt; tbody'); 
    var $tr = $("&lt;tr class='optionAndAnswer' align='center'&gt;");
    var $image = $("&lt;td class='image'&gt;&lt;/td&gt;"); 


var $fileImage = $("&lt;form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return imageClickHandler(this);' class='imageuploadform' &gt;" + 
    "&lt;p class='imagef1_upload_process' align='center'&gt;Loading...&lt;br/&gt;&lt;img src='Images/loader.gif' /&gt;&lt;br/&gt;&lt;/p&gt;&lt;p class='imagef1_upload_form' align='center'&gt;&lt;br/&gt;&lt;label&gt;" + 
    "Image File: &lt;input name='fileImage' type='file' class='fileImage' /&gt;&lt;/label&gt;&lt;br/&gt;&lt;br/&gt;&lt;label class='imagelbl'&gt;" + 
    "&lt;input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /&gt;&lt;/label&gt;" + 
    "&lt;iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'&gt;&lt;/iframe&gt;&lt;/form&gt;");     

    $image.append($fileImage);


    $tr.append($image);  
    $tbody.append($tr); 



}
</code></pre>
