Функция суммирования:
function sum(data, key = n => n) {
const getVal = key instanceof Function ? key : n => n[key];
let result = 0;
for (const n of data) {
result += +getVal(n) || 0;
}
return result;
}
Элементы могут быть представлены как jquery-объект, NodeList или HTMLCollection (ну и разумеется, обычный массив, если что, тоже будет обсчитан как надо):
const $form = $('form').on('change', 'select', () => {
$('#result').val(sum($form.find('select'), n => $(n).val()));
});
const input = document.querySelector('#result');
const selects = document.querySelectorAll('form select');
const onChange = () => input.value = sum(selects, 'value');
selects.forEach(n => n.addEventListener('change', onChange));
document.forms[0].addEventListener('change', function(e) {
if (e.target.tagName === 'SELECT') {
document.getElementById('result').value = sum(
this.getElementsByTagName('select'),
n => n.selectedOptions[0].getAttribute('value')
);
}
});