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 8842915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:05:10+00:00 2026-06-14T11:05:10+00:00

I have a problem with my calculation answer. What ever is entered in the

  • 0

I have a problem with my calculation answer.

What ever is entered in the text input for each answer in a
question, it will subtract the number under the “Total Marks” column
for that question with the numbers entered within the text input for
that question.

Example is below:

Screenshot showing how calculation works

In the text inputs I entered in numbers 1, 1 and 2. The Total Narks under the Total Marks Remaining column was 5 but it is now 1 as 5 – 1 – 1 – 2 = 1 Total Mark Remaining

The problem I have though is that if I change the top text input to lets say 3, then the calculation should now be 5 – 3 – 1 – 2 = -1 Total Mark Remaining. But it doesn’t do this as that somewhere in the jquery function it has stated that if Total Marks Remaining number is less than 0, then display the original Total Marks Remaining number which is 5. This is incorrect, it should just display the minus number so the user knows that they need to reduce 1 mark. How can I get the minus number to be displayed if the Total Marks Remaining number is less than 0?

Below is the code for the jquery function:

Jquery:

    $(function () {
        //alert("here");         
        var questions = $('#markstbl td[class*="_ans"]').length - 1;

        //disable single entry
        for (var i = 0; i <= questions; i++) {
            if ($("[class*=q" + i + "_mark]").length == 1) {
                var t_marks = $("[class*=q" + i + "_ans]").html();
                //alert(t_marks);
                $("[class*=q" + i + "_mark]").val(t_marks)
                    .attr("disabled", "disabled");
                //$("[class*=q"+i+"_mark]").attr("disabled","disabled");
            }
        }

        //find each question set and add listeners
        for (var i = 0; i <= questions; i++) {
            $('input[class*="q' + i + '"]').keyup(function () {
                var cl = $(this).attr('class').split(" ")[1]
                var questionno = cl.substring(cl.indexOf('q') + 1, cl.indexOf('_'));
                var tot_marks = $(".q" + questionno + "_ans_org").val();
                //alert(tot_marks);
                var ans_t = 0;
                $("[class*=q" + questionno + "_mark]").each(function () {
                    var num = (isNaN(parseInt($(this).val()))) ? 0 : parseInt($(this).val());
                    ans_t += parseInt(num);
                });
                ans_t = tot_marks - ans_t;
                //alert(ans_t);
                //var fixedno = tot_marks;
                var ans = (parseInt(ans_t) < 0) ? tot_marks : ans_t;
                $(".q" + questionno + "_ans").val(ans);
                $(".q" + questionno + "_ans_text").html(ans);
            });
        }
    });​

Below is the dynamic HTML Table:

HTML:

<body>
  <table border='1' id='markstbl'>
    <thead>
      <tr>
        <th class='questionth'>Question No.</th>

        <th class='questionth'>Question</th>

        <th class='answerth'>Answer</th>

        <th class='answermarksth'>Marks per Answer</th>

        <th class='noofmarksth'>Total Marks Remaining</th>
      </tr>
    </thead>

    <tbody>
      <?php
      $row_span  = array_count_values($searchQuestionId);
      $prev_ques = '';
      foreach ($searchQuestionId as $key => $questionId) {
      ?>

      <tr class="questiontd">
        <?php
            if ($questionId != $prev_ques) {
        ?>

        <td class="questionnumtd" name="numQuestion" rowspan=
        "<?php echo $row_span[$questionId]; ?>"><?php
                echo $questionId;
        ?><input type="hidden" name="q&lt;?php echo $questionId; ?&gt;_ans_org" class=
        "q&lt;?php echo $questionId; ?&gt;_ans_org" value=
        "<?php echo $searchMarks[$key]; ?>" /><input type="hidden" name=
        "q&lt;?php echo $questionId; ?&gt;_ans" class=
        "q&lt;?php echo $questionId; ?&gt;_ans" value=
        "<?php echo $searchMarks[$key]; ?>" /></td>

        <td class="questioncontenttd" rowspan="<?php echo $row_span[$questionId]; ?>">
        <?php
                echo $searchQuestionContent[$key];
        ?></td><?php
            }
        ?>

        <td class="answertd" name="answers[]"><?php
            echo $searchAnswer[$key];
        ?></td>

        <td class="answermarkstd"><input class=
        "individualMarks q&lt;?php echo $questionId; ?&gt;_mark_0" q_group="1" name=
        "answerMarks[]" id="individualtext" type="text" /></td><?php
            if ($questionId != $prev_ques) {
        ?>

        <td class="noofmarkstd q&lt;?php echo $questionId; ?&gt;_ans_text" q_group="1"
        rowspan="<?php echo $row_span[$questionId]; ?>"><?php
                echo $searchMarks[$key];
        ?></td><?php
            }
        ?>
      </tr><?php
          $prev_ques = $questionId;
      }
      ?>
    </tbody>
  </table>
</body>
</html>
  • 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-14T11:05:12+00:00Added an answer on June 14, 2026 at 11:05 am

    This line is the culprit:

    var ans = (parseInt(ans_t) < 0) ? tot_marks : ans_t;
    

    Change it to:

    var ans = ans_t;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have come across this problem in a calculation I do in my code,
Okay, so the answer to my question might not be the problem but here's
** LOOK AT MY ANSWER WHICH IS REFERE AS NEW QUESTION ON SAME PROBLEM.
Problem: I have two overlapping 2D shapes, A and B, each shape having the
I have not marked this question Answered yet. The current accepted answer got accepted
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with show or hide form in Window Form Application. I start
I have problem with UIWebView delay when the load image from url. In my

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.