JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" class="unitrate" />
<input type="text" class="unitrate" />
<input type="text" id="txtsum" />

JavaScript

$(document).on('keyup', ".unitrate", function (e) {
            calculateunitrateSum();
        });


function calculateunitrateSum() {
            var unitratesum = 0;
            $(".unitrate").each(function () {
                //add only if the value is number
                if (!isNaN(this.value) && this.value.length != 0) {
                    unitratesum += parseFloat(this.value);
                }
                else {
                    $(this).val('0')
                }
            });
            $('#txtsum').val(unitratesum.toFixed(2));
        }