How do I store the final value of balance amount that is being input?
HTML
<div id="balance_amount">
balance amount:
<input type="number" id="balance-amount-input" name="balance_amount" value='+balance_amount+'>
</div>
JS
$('body').on('input','#balance-amount-input', function() {
$('.jconfirm #error-msg').hide();
var balance_amount_tmp=$(this).val();
$('#balance-amount-input').val(balance_amount_tmp);
if ((balance_amount_tmp-account_balance) > 0) {
$('.jconfirm #error-msg').show();
$('.jconfirm #error-msg').html('<p class="alert alert-warning">not enough</p>');
$('.jconfirm-buttons button.btn-success').attr('disabled', 'true');
return;
} else {
offline_amount = (total_amount - balance_amount_tmp).toFixed(2);
$('#offline_amount').html(offline_amount);
$('.jconfirm-buttons button.btn-success').removeAttr('disabled');
return;
}
});
Please help me to solve this!
You can add another hidden input field to pass additional information with the form, or store this information into a variable and add it to the ajax call directly. for example you can use this:
$('body').on('input','#balance-amount-input', function() {
$('.jconfirm #error-msg').hide();
var balance_amount_tmp=$(this).val();
// $('#balance-amount-input').val(balance_amount_tmp); //PTK: you don't need this line
if ((balance_amount_tmp-account_balance) > 0) {
$('.jconfirm #error-msg').show();
$('.jconfirm #error-msg').html('<p class="alert alert-warning">用户余额不足</p>');
$('.jconfirm-buttons button.btn-success').attr('disabled', 'true');
return;
} else {
offline_amount = (total_amount - balance_amount_tmp).toFixed(2);
$('#offline_amount').val(offline_amount); //PTK: I changed here html to val
$('.jconfirm-buttons button.btn-success').removeAttr('disabled');
return;
}
});
<div id="balance_amount">
balance amount:
<input type="number" id="balance-amount-input" name="balance_amount" value='+balance_amount+'>
<input type="hidden" id="offline_amount" name="offline_amount" value="">
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With