Warm tip: This article is reproduced from stackoverflow.com, please click
javascript laravel-5.8

Calculating a value with JS and Storing that value in database

发布于 2020-04-18 09:42:13

I'm calculating 2 value with js:

$('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');`

and trying to store this value:

<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>

I'm getting null value whenever I try to input those JS value My question is: How can I store this Calculated value in DB?

Questioner
optinix
Viewed
40
Meem Fatema 2020-02-07 02:50

Just make this change! and Hope this will work: $("input[name=user_receive_fund_amount]").val(firstValue*secondValue);