Check out this HTML code snippet
<form><input type="number"></form>
<table class="my-table">
<thead>
<tr>
<td>Header 1</td>
<td>Header 2</td>
</tr>
</thead>
<tbody>
<tr data-row-num="1">
<td>Item 1</td>
<td>£0</td>
</tr>
<tr data-row-num="1">
<td>Item 2</td>
<td>£5</td>
</tr>
<tr data-row-num="1">
<td>Item 3</td>
<td>£10</td>
</tr>
</tbody>
I'm trying to multiply the values in the last column of each row by the input value above and display the new values. I've been playing around with some JavaScript but could really use some help.
<script type="text/javascript>
$('input[type=number]').on("input", function () {
var tr = $('input[type=number]').closest('tr');
var num = this.value;
var numerator = tr.find('td:nth-child(2)').text();
tr.find('td:last-child').text('£' + num * numerator);
});
Your assistance would be greatly appreciated!