Калькуляция полей без кнопки
Доброго времени. Очень мало знаю язык, столкнулся с проблемой. Нужна автоматическая калькуляция полей в онлайн режиме без кнопки
Вот сам "код" <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> |
Цитата:
https://learn.javascript.ru/events-change Вешай его на нужные тебе поля... И вызывай в обработчике свою функцию. ;) |
PersonalJesusqe,
добавить во все CFV <input oninput="addIt()" |
Часовой пояс GMT +3, время: 04:09. |