Home > Blockchain >  Get the unique total scores of students
Get the unique total scores of students

Time:01-17

I have a form on my school web application where teachers are able to add scores for students and at the end of each row, the total, which is the sum of input values is automatically calculated per student.

The problem is that it output the total of all the students instead of the total of individual students on all the rows even ones with no scores added.

How do I get the unique total value for each row?

scores form

Below is my code

<?php if($class_id >= 1 && $class_id <= 4 && $student['is_secmid'] == 1){?>

<form method="post" action="<?php echo site_url('admin/examgroup/entrymarks') ?>" id="assign_form1111">

    <input type="hidden" id="max_mark" value="<?php echo $subject_detail->max_marks; ?>">
 <?php

    if (isset($resultlist) && !empty($resultlist)) {

        ?>
<div >
  <div >
 <input type="hidden" name="exam_group_class_batch_exam_subject_id" value="<?php echo $exam_group_class_batch_exam_subject_id; ?>">
 <div >
<table >
<thead>
<tr>
<th>C.A 1 (10.0)</th>
<th>C.A 2 (10.0)</th>
     </tr>
</thead>
 <tbody>
<?php if (empty($resultlist)) {
?>
<tr>
<td colspan="7" ><?php echo $this->lang->line('no_record_found'); ?></td>
</tr>
<?php
} else {
foreach ($resultlist as $student) {
?>
<tr >
<input type="hidden" name="prev_id[<?php echo $student['exam_group_class_batch_exam_students_id'] ?>]" value="<?php echo $student['exam_group_exam_result_id'] ?>">
 <input type="hidden" name="exam_group_student_id[]" value="<?php echo $student['exam_group_class_batch_exam_students_id'] ?>">
<td><?php echo $student['admission_no']; ?></td>
<td style="white-space: nowrap;"><?php echo $student['lastname'] . " " . $student['firstname']; ?></td>
<td> <input type="number"  min="0" max="10" name="exam_group_student_ca1_<?php echo $student['exam_group_class_batch_exam_students_id']; ?>" value="<?php echo $student['exam_group_exam_result_get_ca1']; ?>" step="any"></td>

<td> <input type="number"  min="0" max="10" name="exam_group_student_ca2_<?php echo $student['exam_group_class_batch_exam_students_id']; ?>" value="<?php echo $student['exam_group_exam_result_get_ca2']; ?>" step="any"></td>

<td> <output ></output></td>
</tr>
<?php
}
}
 ?>
</tbody>
</table>
</div>

<?php if ($this->rbac->hasPrivilege('exam_marks', 'can_edit')) { ?>

  <button type="submit"  id="load" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Please Wait.."><?php echo $this->lang->line('save'); ?>

    </button>

    <?php } ?>

  </div>

</div>
<?php } ?>
<script>
const $inputs = $('input[type="number"]')

$inputs.change(function() {
  var total = 0;
  var parent = $(this).closest('.row');
  parent.find('input[type="number"]').each(function() {
    if ($(this).val() != '') {
      total  = parseInt($(this).val());
    }
  });
  parent.find('.result').html(total);
});

</script>

CodePudding user response:

you missed the class row on <tr> and you are trying to find it on closest div from javascript, so you are getting this (<div >) and it have all the (<input type="number").

you forget to add class to TR. Add class row on <tr> so you can get all (<input type="number") inside the tr.

because of not added class on TR you are facing issue that all total have same numbers.

  • Related