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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:56:27+00:00 2026-06-14T10:56:27+00:00

I have a jsfiddle here Please look at Question 2 in the jsfiddle table

  • 0

I have a jsfiddle here

Please look at Question 2 in the jsfiddle table as that question contains only a single answer.

In the jquery function what I have tried to do it state that if a question only
contains 1 answer, then the text input under the Marks Per Answer
column for that answer should be readonly and display the same value
as the Total Marks Remaining for that question.

Also if you look in the jsfiddle, it states that under Total Marks Remaining column for that single row, it displays the number 5, it should display number 0. As that number 5 in the readonly text input minus the original number for total marks Remaining (which was 5) means that the number under Total Marks Remaining should be 0 for that row.

My question is that what do I need to include in the jquery function in the jsfiddle so that:

  1. if a question has a single answer, that text input is readonly

  2. displays the total marks number in the text input

  3. displays 0 under “Total Marks Remaining” for that row as it should
    of perform the calculation between the number in the read only text
    input and the original Total Marks Remaining number.

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:

    <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='totalmarksth'>Total Marks</th>
<th class='emptyth'></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<?php echo$questionId?>_ans_org" class="q<?php echo$questionId?>_ans_org" value="<?php echo$searchMarks[$key]?>"><input type="hidden" name="q<?php echo$questionId?>_ans" class="q<?php echo$questionId?>_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<?php echo$questionId?>_mark_0"  q_group="1" name="answerMarks[]" id="individualtext" type="text" />
</td>
<?php
    if($questionId != $prev_ques){
    ?>
<td class="totalmarkstd" rowspan="<?php echo$row_span[$questionId]?>"><?php echo$totalMarks[$key]?></td>
<td class="noofmarkstd q<?php echo$questionId?>_ans_text"  q_group="1" rowspan="<?php echo$row_span[$questionId]?>"><?php echo"<strong>Marks Remaining:<br/>".$searchMarks[$key]."</strong>"?></td>
<?php
    }
    ?>
</tr>
<?php
$prev_ques = $questionId;
}
?>
</tbody>
</table>
  • 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-14T10:56:28+00:00Added an answer on June 14, 2026 at 10:56 am

    Your disabling loop is only checking the first of the two questions; a classic out-by-one error. Try this:

    var questions = $('#markstbl td[class*="_ans"]').length;
    

    questions will now be 2 instead of 1 and both questions will be looped over.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jsfiddle here . jQuery $(function() { //var input = $('form :input[type=text]')
I have created a JSFiddle of my case here: http://jsfiddle.net/gGCaX/ (Please take a look,
I have a jsfiddle here . What happens is that if you select a
I have a Jsfiddle application here . If you type in a question in
My script is here : jsfiddle i have two attributes in my form that
I have a fiddle here http://jsfiddle.net/WULsZ/1/ I load jQuery first and the code is
I have this type of exercise in jquery. Go here http://jsfiddle.net/LAntL/3/ For Item 1
I have a jsfiddle here: http://jsfiddle.net/ybZvv/61/ Please follow steps in fiddle: When you open
This question is related to this question yesterday . Please see current jsfiddle here
Look at my codes here please : http://jsfiddle.net/FVcJz/7/ when we hover on the text,

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.