How to correct this variable
<p>I have a variable issue below:</p>

<pre><code> function validation() {

                var context = $('#optionAndAnswer');
    var currenttotal = context.find('.answerBtnsOn').length;    

    alertValidation= "";
        // Note, this is just so it's declared...

    $(".numberAnswerTxtRow").each(function() {
    if (!this.value) {
        alertValidation += "\nPlease Enter in the Number of Answers you Require for this question\n";
    }
else if (currenttotal &gt; $(this).val()){
    alertValidation += "\nYou have selected more answers than the required amount\n";
}

else if (currenttotal &lt; $(this).val()) {
    alertValidation += "\nYou have selected less answers than the required amount\n";
}
});
</code></pre>

<p>}</p>

<p>The problem is that for each row, it should look at the number entered in the .numberAnswerTxtRow textbox and see how many buttons (.answerBtnsOn.length) have been selected. If more buttons are selected than the figure entered in the textbox then, it should display alert that you have selected more answers than required. If vice versa it should do the same except display message stating you select less answers than required. The problem is that it doesn't recognise the figure entered in textbox and the amount of buttons selected for each row. This begs me to believe that I need to change the <code>var context</code> and <code>var currenttotal</code> to something else so it recognises the textbox and buttons selected for each row. What should I change these variables to?</p>

<p>Below is jquery code where the textbox and answers come from:</p>

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

            var context = $('#optionAndAnswer');
    var currenttotal = context.find('.answerBtnsOn').length;  

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

        $('.numberAnswerTxt', context).each(function() {
            var $this = $(this);
            var $noofanswersText = '';

                $noofanswersText = $("&lt;input type='text' class='numberAnswerTxtRow answertxt' style='display: block;' onkeyup='numberKeyUp(this)' onkeypress='return isNumberKey(event)' onChange='getButtons()'&gt;").attr('name', $this.attr('name')).attr('value', $this.val())    
            }
            $noofanswers.append($noofanswersText);
        });

        var $this, i=0, $row, $cell;
        $('#optionAndAnswer .answers').each(function() {
            $this = $(this);
            if(i%7 == 0) {
                $row = $("&lt;tr/&gt;").appendTo($answer);
                $cell = $("&lt;td/&gt;").appendTo($row);
            }
            var $newBtn = $("&lt;input class='answerBtnsRow answers' type='button' style='display:%s;' onclick='btnclick(this);' /&gt;".replace('%s',$this.is(':visible')?'inline-block':'none')).attr('name', $this.attr('name')).attr('value', $this.val()).attr('class', $this.attr('class'));
            $newBtn.appendTo($cell);
            i++;
        });

        $tr.append($answer);
        $tr.append($noofanswers);
        $tbody.append($tr);
    }
</code></pre>

<p>The rows are added into a table known as qandatbl:</p>

<pre><code>&lt;table id="qandatbl" align="center"&gt;
&lt;thead&gt;
&lt;tr&gt;
    &lt;th class="noofanswers"&gt;Number of Answers&lt;/th&gt;
    &lt;th class="answer"&gt;Answer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;/tbody&gt;
&lt;/table&gt;
</code></pre>
