Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:05:30+00:00 2026-06-15T10:05:30+00:00

I’m using the following HTML code to display a table: <form id=Marks action=/u0877654/Mobile/individualmarks.php method=post>

  • 0

I’m using the following HTML code to display a table:

<form id="Marks" action="/u0877654/Mobile/individualmarks.php" method="post">   

<table border='1' id='markstbl'>
<thead>
<tr>
<th class='questionth'>Question No.</th>
<th class='answermarksth'>Marks per Answer</th>
<th class='noofmarksth'>Marks Remaining</th>
</tr>
</thead>
<tbody>

<tr class="questiontd">
<td class="questionnumtd q<?php echo$questionId?>_qnum" name="numQuestion" rowspan="1">1 <input type="hidden" name="q1_ans_org" class="q1_ans_org" value="5"><input type="hidden" name="q1_ans" class="q1_ans" value="5"></td>
<td class="answermarkstd">
<input class="individualMarks q1_mark"  q_group="1" name="answerMarks[]" class="individualtext" type="text" onkeypress="return isNumberKey(event)" maxlength="3" />
</td>
<td class="noofmarkstd q1_ans_text"  q_group="1" rowspan="1"><strong>5</strong></td>
</tr>

<tr class="questiontd">
<td class="questionnumtd q<?php echo$questionId?>_qnum" name="numQuestion" rowspan="1">2 <input type="hidden" name="q2_ans_org" class="q2_ans_org" value="5"><input type="hidden" name="q2_ans" class="q2_ans" value="5"></td>
<td class="answermarkstd">
<input class="individualMarks q2_mark"  q_group="1" name="answerMarks[]" class="individualtext" type="text" onkeypress="return isNumberKey(event)" maxlength="3" />
</td>
<td class="noofmarkstd q2_ans_text"  q_group="1" rowspan="1"><strong>5</strong></td>
</tr>
</tbody>
</table>

<p><input id="submitBtn" name="submitMarks" type="submit" value="Submit Marks" /></p>

</form>

Below is what the table looks like:

Question No.     Marks Per Answer          Marks Remaining
    1            (value=5 text input)         0
    2            (blank text input)           5

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:

Higher than 0:

You have errors on Question Number: 
Your Total Marks Remaining does not equal 0 

• You Have NaN Marks Remaining

Less than 0:

You have errors on Question Number: 
Your Total Marks Remaining does not equal 0 

• You Need To Remove NaN Marks

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:

You have errors on Question Number: 

• You have not entered in a value for all the Indivdiaul Marks textbox

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.

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.

How can the two problems above be fixed?

This is my jQuery 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 < '0') {

            alertValidation = "Your Total Marks Remaining does not equal 0 \n\n\u2022 You Need To Remove " + Math.abs(marks) + " Marks";
        } else if (marks > '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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:05:31+00:00Added an answer on June 15, 2026 at 10:05 am

    You’re comparing Strings when you do $("[class*=q" + i + "_mark]").text() < '0', so try the != (Not Equal) operator versus the < (Less Than). Example:

     $("[class*='q'").each(function (i) {
                var marks = parseInt($("[class*=q" + i + "_mark]").text());
                _qid = $(".q" + i + "_ans_org").text();
                _msg = "You have errors on Question Number: " + _qid + "\n";
    
    
                if (!this.value) {
                    alertValidation += "\n\u2022 You have not entered in a value for all the Indivdiaul Marks textbox\n";
                }
    
                if ($("[class*=q" + i + "_mark]").text() != '0') {
                    alertValidation = "Your Total Marks Remaining does not equal 0 \n\n\u2022 You Need To Remove " + Math.abs(marks) + " Marks";
                } else {
                    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 
                }    
            });
    

    Otherwise use your variable:

     $("[class*='q'").each(function (i) {
                var marks = parseInt($("[class*=q" + i + "_mark]").text());
                _qid = $(".q" + i + "_ans_org").text();
                _msg = "You have errors on Question Number: " + _qid + "\n";
    
    
                if (!this.value) {
                    alertValidation += "\n\u2022 You have not entered in a value for all the Indivdiaul Marks textbox\n";
                }
    
                if (marks < 0) {
                    alertValidation = "Your Total Marks Remaining does not equal 0 \n\n\u2022 You Need To Remove " + Math.abs(marks) + " Marks";
                } else if (marks > 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 
                }    
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.