JSFiddle - React, Tailwind, and code Playground
by George Bash
HTML
<form>
<p><input type="text" name="spec1" id="a" value="39"> <label>(a) Масса/Вес (в тоннах)</label></p>
<p><input type="text" name="spec2" id="b" value="590"> <label>(b) Мощность двигателя (л.с.)</label></p>
<p><input type="text" name="spec3" id="c" value="18"> <label>(c) Удельная мощность (л.с./т)</label></p>
<p><input type="text" name="spec3" id="d" value="55"> <label>(d) Максимальная скорость по склону(км/ч)</label></p>
<p><b>Скорость массы по ровной поверхности: <output name="o" for="a b c d e f g">0</output> км/ч</b></p>
</form>
JavaScript
window.addEventListener('DOMContentLoaded', function speed() {
var form = document.querySelector('form'),
elem = form.querySelectorAll('[name^="spec"]'),
output = form.querySelector('output');
function total()
{
output.innerHTML = [].reduce.call( elem, function(sum, el) {
var n = (+el.value||0) * (el.checked || el.tagName == "SELECT" || el.type == "text");
return sum + n
},0);
}
form.addEventListener('change', total);
form.addEventListener('input', total);
});