//Put the function on top of the single execution construct
var updateTotal = function () {
var qtyStr = parseInt($('#quotedetail-qty').val());
var amountStr = parseInt($('#costeach').val());
var qty = isNaN(qtyStr) ? 0 : qtyStr;
var amount = isNaN(amountStr) ? 0 : amountStr;
var totalAmount = qty * amount;
if (totalAmount > 100000) {
totalAmount = '';
}
$('#quotedetail-cost').val(totalAmount);
};
//Now go ahead do catch the keyup events
$(document).on('keypress', '#quotedetail-qty', function () {
updateTotal();
})on('keypress', '#costeach', function () {
updateTotal();
});
use backend\assets\AppAsset;
AppAsset::register($this);
Asset file
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@themes';
public $css = [
'css/site.css',
];
public $js = [
'/backend/themes/js/ajax-modal-popup.js'
];
public $depends = [
'yii\web\YiiAsset',
];
}
JS file
//Put the function on top of the single execution construct
var updateTotal = function () {
var qtyStr = parseInt($('#quotedetail-qty').val());
var amountStr = parseInt($('#costeach').val());
var qty = isNaN(qtyStr) ? 0 : qtyStr;
var amount = isNaN(amountStr) ? 0 : amountStr;
var totalAmount = qty * amount;
if (totalAmount > 100000) {
totalAmount = '';
}
$('#quotedetail-cost').val(totalAmount);
};
//Now go ahead do catch the keyup events
$(document).on('keypress', '#quotedetail-qty', function () {
updateTotal();
})on('keypress', '#costeach', function () {
updateTotal();
});