使用JS计算值并将该值存储在数据库中

问题描述 投票:1回答:1

我正在使用js计算2个值:

$('input').keyup(function(){ // run anytime the value changes
    var firstValue  = Number($('#user_send_fund_amount').val());
    var secondValue = Number($('#fixed_amount').val());
    document.getElementById('user_receive_fund_amount').value = firstValue * secondValue ;});

并尝试存储此值:

<form  method="POST" class="form-register" action="{{ route('order.store') }}">
 @csrf
   <input id="user_send_fund_amount" type="number" class="form-control"
     name="user_send_fund_amount" required>
    <input type="number" value="{{$receive->buy}}" class="form-control"
        id="fixed_amount" hidden>
    <input type="number" class="form-control" id="user_receive_fund_amount" name="user_receive_fund_amount" readonly/>
</form>

I'm getting null value whenever I try to input those JS value我的问题是:如何在数据库中存储此计算值?

javascript laravel-5.8
1个回答
0
投票

您的代码在此行中有语法错误:

document.getElementById('user_receive_fund_amount').value = firstValue * secondValue ;});

从末尾删除;})。因此,该行变为:

document.getElementById('user_receive_fund_amount').value = firstValue * secondValue;
© www.soinside.com 2019 - 2024. All rights reserved.