JSFiddle - React, Tailwind, and code Playground
HTML
<table>
<tr class="parent-realtor percent-text">
<td>
<h5>Realtor Percent</h5>
</td>
<td>
<input type="text" class="percent-total" />
<input type="text" onfocus="this.blur()" class="percent-data" />
</td>
<td>
<input type="text" class="percent-total" />
<input type="text" onfocus="this.blur()" class="percent-data" />
</td>
<td>
<input type="text" class="percent-total" />
<input type="text" onfocus="this.blur()" class="percent-data" />
</td>
<td>
<input type="text" class="percent-total" />
<input type="text" onfocus="this.blur()" class="percent-data" />
</td>
</tr>
<tr>
<td>
<h6>Contract Amount</h6>
</td>
<td>
<input type="text" data-parent="realtor" />
</td>
<td>
<input type="text" data-parent="realtor" />
</td>
<td>
<input type="text" data-parent="realtor" />
</td>
<td>
<input type="text" data-parent="realtor" />
</td>
</tr>
<tr class="percent-text">
<td>
<h6>Buyer's Agent</h6>
</td>
<td>
<input type="text" data-parent="realtor" class="percent" />
<input type="text" data-parent="realtor" class="percent-data r" onfocus="this.blur()" />
</td>
<td>
<input type="text" data-parent="realtor" class="percent" />
<input type="text" data-parent="realtor" class="percent-data r" onfocus="this.blur()" />
</td>
<td>
<input type="text" data-parent="realtor" class="percent" />
<input type="text" data-parent="realtor" class="percent-data r" onfocus="this.blur()" />
</td>
<td>
<input type="text" data-parent="realtor" class="percent" />
<input type="text"...
CSS
table input {
width: 50px;
}
table h5, h6 {
width: 55px;
}
.percent, .percent-total {
width:20px
}
.percent-data {
width:50px
}
JavaScript
$('.percent').on('keyup', function () {
//calcRealtor();
var totals = [0, 0, 0, 0, 0, 0, 0, 0],
parent_name = $(this).data('parent'),
find_parent_row = $('tr.parent-realtor');
find_parent_row.nextUntil('[class="parent-realtor"]').find('input[data-parent="realtor"]').each(function () {
totals[$(this).parent('td').index() / 1 - 1] += +this.value;
});
find_parent_row.find('input').each(function (i) {
this.value = totals[i];
});
});