I need some help with dynamically calculating an HTML table column using data from other columns and using a user-defined equation.
For example, if the user inputs the equation C1 + C2 * 0.5 + C3 * 0.8
into a input box the table would need to calculate the last column based on the data from the columns defined in the equation (C1 = column 1, C2 = column 2...).
My table data looks like this:
Student ID | Homework 1 | Homework 2 | Exam points | Final Grade
1 8.75 7.60 55.50 -
2 9.00 4.50 63.00 -
3 7.75 7.40 45.50 -
If the user typed in the equation C1 + C2 * 0.5 + C3 * 0.8
in the input the table should perform the operations and fill the column Final Grade based on that equation.
The result should look something like this.
Student ID | Homework 1 | Homework 2 | Exam points | Final Grade
1 8.75 7.60 55.50 56.95
2 9.00 4.50 63.00 61.65
3 7.75 7.40 45.50 47.85
The first row in final grade would be calcualted like this (8.75 + 7.60 * 0.5 + 55.50 * 0.8).
This is my body in HTML:
<div>
<input id="equation">
</div>
<table>
<tr>
<th>Student ID</th>
<th>Homework 1</th>
<th>Homework 2</th>
<th>Exam points</th>
<th>Final grade</th>
</tr>
<tr>
<td>1</td>
<td>8.75</td>
<td>7.60</td>
<td>55.50</td>
<td class="final-grade">-</td>
</tr>
<tr>
<td>2</td>
<td>9.00</td>
<td>4.50</td>
<td>63.00</td>
<td class="final-grade">-</td>
</tr>
<tr>
<td>3</td>
<td>8.75</td>
<td>7.60</td>
<td>55.50</td>
<td class="final-grade">-</td>
</tr>
</table>
Any help would be greatly appreciated!