#javascript #html #laravel
Вопрос:
Я столкнулся с проблемой, когда мне нужно обновить значение при вводе значений в поля ввода. В структуре laravel также есть переменная, извлеченная из базы данных.
У меня есть поле, в котором указывается общая сумма задолженности и применяется надбавка eftpos к сумме в качестве ссылки на то, сколько требуется заплатить через eftpos.
Я хотел бы обновить это поле на основе нового баланса-добавляются наличные/Чек или суммы стипендий (поскольку это не облагается доплатой eftpos). Идея состоит в том, чтобы убедиться, что мы правильно применяем надбавку EFTPOS к сумме eftpos.
HTML-код
<table class="table">
<thead class="text-primary">
<th class="text-center">Method</th>
<th class="text-center">Amount</th>
<th></th>
</thead>
<tbody>
<tr>
<td class="text-center">EFTPOS</td>
<td class="text-center">$ <input type="number" step="0.01" name="eftpos"></td>
<td class="text-center"><a id="eftpos"> ${{ number_format(($income $student->AdditionalItems->where('paid', 0)->sum('amount'))*(1 $eftpos), 2)}}</a> - Including Surcharge</td>
</tr>
<tr>
<td class="text-center">Cash</td>
<td class="text-center" id="cash">$ <input type="number" step="0.01" name="cash"></td>
<td></td>
</tr>
<tr>
<td class="text-center">Cheque</td>
<td class="text-center" id="cheque">$ <input type="number" step="0.01" name="cheque"></td>
<td></td>
</tr>
<tr>
<td class="text-center">Scholarship</td>
<td class="text-center" id="scholarship">$ <input type="number" step="0.01" name="scholarship"></td>
<td></td>
</tr>
</tbody>
</table>
Код Javascript
<script type="text/javascript">
window.onload = function () {
var cash = document.getElementById('cash');
cheque = document.getElementById('cheque');
scholarship = document.getElementById('scholarship');
total = document.getElementById('total');
eftpos = 1 {!! json_encode($eftpos, JSON_HEX_TAG) !!};
trigFunc = function(){
eftpos.value = (total.value - (cash.value cheque.value scholarship.value))*eftpos.value;
document.getElementById('eftpos').innerHTML = eftpos.value;
console.log(eftpos.value);
}
cash.onchange = trigFunc;
cheque.onchage = trigFunc;
scholarship.onchange = trigFunc;
}
Значение $eftp передается контроллером laravel
Заранее спасибо за вашу помощь