如何计算另一个输入框中的html输入框值

时间:2018-10-09 11:36:08

标签: javascript php jquery html

以下表格正在从前两列(不包括序列号)中访问mysql表中的值,并在第四列中输入“获得的标记”。在获得分数之后,我还做了三列,分别是“百分比”,“等级”和注释。当用户在“获得的标记”列中输入标记并导航到第二行中的下一个输入框时,我想自动计算百分比:

<table id = "result" class="data-table">

        <caption class="title"></caption>
        <thead>
            <tr>    
                <th><strong>Sr.No.</strong></th>
                <th><strong>Student ID</strong></th>
                <th align="center"><strong>Student Name</strong></th>
                <th style="text-align: center;"><strong>Obtained Marks</strong></th>
                <th style="text-align: center;"><strong>Percentage</th>
                <th style="text-align: center;"><strong>Grade</strong></th>
                <th style="text-align: center;"><strong>Remarks</strong></th>

            </tr>
        </thead>
        <tbody>
        <?php
        $no     = 1;
        $total  = 0;
        while ($row = mysqli_fetch_array($query)) {
            $stu  = $row['stu_id'] == 0 ? '' : number_format($row['stu_id']);
            echo '<tr>
                    <td>'.$no.'</td>
                    <td>'.$row['student_id'].'</td>
                    <input type="hidden" name="student_id[]" value='.$row['student_id'].'>
                    <td style="text-align: left;">'.$row['student_name'].'</td>
                    <input type="hidden" name="student_name[]" value='.$row['student_name'].'>
                    <td>'."<input name='obtmarks[]' placeholder='' class='form-control'  type='number' required='required' style='width: 120px;'>".'</td>
                    <td>'."<input name='percentage[]' placeholder='' class='form-control'  type='number' required='required' style='width: 120px;'>".'</td>
                    <td>'."<input name='grade[]' placeholder='' class='form-control'  type='number' required='required' style='width: 120px;'>".'</td>
                    <td>'."<input name='remarks[]' placeholder='' class='form-control'  type='number' required='required' style='width: 120px;'>".'</td>
                    <input type="hidden" name="class[]" value='.$row['class'].'>
                    <input type="hidden" name="test_date[]" value='.$test_Date.'>
                    <input type="hidden" name="test_subject[]" value='.$Subject_type.'>
                    <input type="hidden" name="test_type[]" value='.$TestType.'>

                </tr>';

            $total += $row['stu_id'];
            $no++;

        }

        ?>
</tbody>
    </table>

1 个答案:

答案 0 :(得分:1)

您可以简单地通过使用<input type="text"/>的{​​{1}}事件来实现。为此,您也有“总分”以获取获得的分值的百分比。 使用此脚本

onkeyup('calculateFn()')

此处的ID是必填文本字段的相应ID。 希望这对您有所帮助。