JSFiddle - React, Tailwind, and code Playground
HTML
<form id="frm1" action="post">
<fieldset>
<legend>form1</legend>
<input type="text" name="a[]">
<input type="text" name="b[]">
<input type="text" name="sum[]">
</fieldset>
<input type="submit" value="calculate">
</form>
<form id="frm2" action="post">
<fieldset>
<legend>form2</legend>
<input type="text" name="a[]">
<input type="text" name="b[]">
<input type="text" name="sum[]">
</fieldset>
<input type="submit" value="calculate">
</form>
CSS
input[type=submit] {
display: none;
}
JavaScript
$('input[type=submit]').click(function(e) {
e.preventDefault();
var thisForm = $(this).parents('form').attr('id');
var valA = $('#'+thisForm+' input[type=text]:first-of-type').val();
var valB = $('#'+thisForm+' input[type=text]:nth-of-type(2)').val();
var sumAB = +valA + +valB;
console.log(sumAB);
$('#'+thisForm+' fieldset input:last-of-type').val(sumAB);
})