温馨提示:本文翻译自stackoverflow.com,查看原文请点击:javascript - Calculating a value with JS and Storing that value in database
javascript laravel-5.8

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

发布于 2020-04-18 11:40:34

我正在用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 ;
document.getElementById('user_receive_fund_amount').setAttribute('readOnly', true);
document.getElementById('user_receive_fund_amount').removeAttribute('readOnly');`

并尝试存储此值:

<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"/>
</form>

每当我尝试输入那些JS值时,我都会得到空值 我的问题是:如何将计算出的值存储在DB中?

查看更多

提问者
optinix
被浏览
40
Meem Fatema 2020-02-07 02:50

只需进行此更改!并希望这会起作用: $("input[name=user_receive_fund_amount]").val(firstValue*secondValue);