Note that there are some explanatory texts on larger screens.

plurals
  1. POit keeps displaying NaN
    primarykey
    data
    text
    <p>I'm using the following HTML code to display a table:</p> <pre><code>&lt;form id="Marks" action="/u0877654/Mobile/individualmarks.php" method="post"&gt; &lt;table border='1' id='markstbl'&gt; &lt;thead&gt; &lt;tr&gt; &lt;th class='questionth'&gt;Question No.&lt;/th&gt; &lt;th class='answermarksth'&gt;Marks per Answer&lt;/th&gt; &lt;th class='noofmarksth'&gt;Marks Remaining&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr class="questiontd"&gt; &lt;td class="questionnumtd q&lt;?php echo$questionId?&gt;_qnum" name="numQuestion" rowspan="1"&gt;1 &lt;input type="hidden" name="q1_ans_org" class="q1_ans_org" value="5"&gt;&lt;input type="hidden" name="q1_ans" class="q1_ans" value="5"&gt;&lt;/td&gt; &lt;td class="answermarkstd"&gt; &lt;input class="individualMarks q1_mark" q_group="1" name="answerMarks[]" class="individualtext" type="text" onkeypress="return isNumberKey(event)" maxlength="3" /&gt; &lt;/td&gt; &lt;td class="noofmarkstd q1_ans_text" q_group="1" rowspan="1"&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="questiontd"&gt; &lt;td class="questionnumtd q&lt;?php echo$questionId?&gt;_qnum" name="numQuestion" rowspan="1"&gt;2 &lt;input type="hidden" name="q2_ans_org" class="q2_ans_org" value="5"&gt;&lt;input type="hidden" name="q2_ans" class="q2_ans" value="5"&gt;&lt;/td&gt; &lt;td class="answermarkstd"&gt; &lt;input class="individualMarks q2_mark" q_group="1" name="answerMarks[]" class="individualtext" type="text" onkeypress="return isNumberKey(event)" maxlength="3" /&gt; &lt;/td&gt; &lt;td class="noofmarkstd q2_ans_text" q_group="1" rowspan="1"&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;&lt;input id="submitBtn" name="submitMarks" type="submit" value="Submit Marks" /&gt;&lt;/p&gt; &lt;/form&gt; </code></pre> <p>Below is what the table looks like:</p> <pre><code>Question No. Marks Per Answer Marks Remaining 1 (value=5 text input) 0 2 (blank text input) 5 </code></pre> <p>Now I have created validations for the table above using jquery. If a row contains any number except for 0 (either higher or lower) then it will display an alert stating:</p> <p><strong>Higher than 0:</strong></p> <pre><code>You have errors on Question Number: Your Total Marks Remaining does not equal 0 • You Have NaN Marks Remaining </code></pre> <p><strong>Less than 0:</strong></p> <pre><code>You have errors on Question Number: Your Total Marks Remaining does not equal 0 • You Need To Remove NaN Marks </code></pre> <p>Another validation is that if the user has left a text input blank under "Marks Per Answer" column theni it should display this message below:</p> <pre><code>You have errors on Question Number: • You have not entered in a value for all the Indivdiaul Marks textbox </code></pre> <p>I have two problems though as you can see. First of all it does not display the number for which question number contains the error, it should display question number for the first question which contains an error.</p> <p>The other problem is that it keeps displaying NaN. It should display how many marks need to be removed to make it 0 or added to make it 0.</p> <p>How can the two problems above be fixed?</p> <p>This is my jQuery code:</p> <pre><code>function validation() { var alertValidation = ""; var _qid = ""; var _msg = ""; $("[class*='q']").each(function (i) { var questions = parseInt($("[class*=q" + i + "_qnum]").text()); var marks = parseInt($("[class*=q" + i + "_ans_text]").text()); var txtinput = $("[class*=q" + i + "_mark]").val(); _qid = questions; _msg = "You have errors on Question Number: " + _qid + "\n"; if (txtinput == '' || txtinput == null) { alertValidation += "\n\u2022 You have not entered in a value for all the Indivdiaul Marks textbox\n"; } else if (marks &lt; '0') { alertValidation = "Your Total Marks Remaining does not equal 0 \n\n\u2022 You Need To Remove " + Math.abs(marks) + " Marks"; } else if (marks &gt; '0') { alertValidation = "Your Total Marks Remaining does not equal 0 \n\n\u2022 You Have " + marks + " Marks Remaining"; } if (alertValidation != "") { return false; //Stop the each loop } }); if (alertValidation != "") { alert(_msg + alertValidation); return false; } return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload