Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Калькуляция полей без кнопки (https://javascript.ru/forum/misc/84147-kalkulyaciya-polejj-bez-knopki.html)

PersonalJesusqe 15.06.2022 16:43

Калькуляция полей без кнопки
 
Доброго времени. Очень мало знаю язык, столкнулся с проблемой. Нужна автоматическая калькуляция полей в онлайн режиме без кнопки

Вот сам "код"

<span>Маржа</span>
 <input name="CFV[917157]"  id="output"class="linked-form__cf js-control-allow-numeric-negative text-input" type="numeric" value="" placeholder="..." autocomplete="off" />
 <hr>
 <span>Бюджет</span>
 <input name="CFV[917159]" class="linked-form__cf js-control-allow-numeric-negative text-input" type="numeric" value="" placeholder="..." autocomplete="off" />
 <hr>
 <span>Себестоимость</span>
 <input name="CFV[917161]" class="linked-form__cf js-control-allow-numeric-negative text-input" type="numeric" value="" placeholder="..." autocomplete="off" />
 <hr>
 <span>Логистика</span>
 <input name="CFV[917163]" class="linked-form__cf js-control-allow-numeric-negative text-input" type="numeric" value="" placeholder="..." autocomplete="off" />
 <hr>
 <span>Агентские</span>
 <input name="CFV[917165]" class="linked-form__cf js-control-allow-numeric-negative text-input" type="numeric" value="" placeholder="..." autocomplete="off" />


<input type="button" value="Add" onclick="addIt()">



<script type="text/javascript">
<!--
function addIt() {
var s1 = parseInt(document.getElementsByName('CFV[917159]')[0].value);
var s2 = parseInt(document.getElementsByName('CFV[917161]')[0].value);
var s3 = parseInt(document.getElementsByName('CFV[917163]')[0].value);
var s4 = parseInt(document.getElementsByName('CFV[917165]')[0].value);    
document.getElementsByName('CFV[917157]')[0].value = s1 - s2 - s3 - s4;
}
// -->
</script>

ksa 15.06.2022 16:48

Цитата:

Сообщение от PersonalJesusqe
Нужна автоматическая калькуляция полей в онлайн режиме без кнопки

Выбирай нужное тебе событие...
https://learn.javascript.ru/events-change

Вешай его на нужные тебе поля... И вызывай в обработчике свою функцию. ;)

рони 15.06.2022 16:48

PersonalJesusqe,
добавить во все CFV
<input oninput="addIt()"


Часовой пояс GMT +3, время: 15:30.