0
我正在Yii2動態表單中工作,但我需要添加一些小函數來添加,子和相乘2個字段並將值放在第三個。我寫了一些代碼,但我無法在textfield上調用該函數。Yii2-動態表單
如何調用字段中的函數?
<script type="text/javascript">
function earnings()
{
var bs = document.getElementById('basic_salary').value;
var da = document.getElementById('dra').value;
var ta = document.getElementById('tra').value;
var gs = parseInt(bs) + parseInt(da) + parseInt('ta');
if (!isNaN(gs))
{
document.getElementById('gross_salary').value = gs;
}
}
function deduct()
{
var lv = document.getElementById('leave').value;
var pd = document.getElementById('per_day').value;
var ra = parseInt(lv) * parseInt(pd);
if (!isNaN(ra))
{
document.getElementById('reduced_amount').value = result;
}
}
function net()
{
var gs = document.getElementById('gross_salary').value;
var ra = document.getElementById('reduced_amount').value;
var ns = parseInt(gs) - parseInt(ra);
if (!isNaN(ns))
{
document.getElementById('net_salary').value = ns;
}
}
</script>
<h4 class="box-title text-aqua"><?php echo Yii::t('payroll', 'Earnings'); ?></h4>
<div class="col-xs-12 col-lg-12 no-padding">
<div class="col-xs-12 col-sm-6 col-lg-6">
<?= $form->field($model, 'basic_salary')->textInput(['maxlength' => 30,
'placeholder' =>$model->getAttributeLabel('basic_salary')], ['id'=>'basicSalary']) ?>
</div>
<div class="col-xs-12 col-sm-6 col-lg-6">
<?= $form->field($model, 'dra')->textInput(['maxlength' => 30,
'placeholder' => $model->getAttributeLabel('dra')], ['id'=>'dearnessAllowance']) ?>
</div>
</div>
<div class="col-xs-12 col-lg-12 no-padding">
<div class="col-xs-12 col-sm-6 col-lg-6">
<?= $form->field($model, 'tra')->textInput(['maxlength' => 30,
'placeholder' => $model->getAttributeLabel('tra')], ['id'=>'travelAllowance']) ?>
</div>
<div class="col-xs-12 col-sm-6 col-lg-6">
<?= $form->field($model, 'gross_salary')->textInput(['maxlength' => 30,
'placeholder' => $model->getAttributeLabel('gross_salary')], ['id'=>'grossSalary']) ?>
</div>
</div>
<h4 class="box-title text-aqua"><?php echo Yii::t('payroll', 'Deduction'); ?></h4>
<div class="col-xs-12 col-lg-12 no-padding">
<div class="col-xs-12 col-sm-6 col-lg-6">
<?= $form->field($model, 'leave')->textInput(['maxlength' => 30,
'placeholder' => $model->getAttributeLabel('leave')]) ?>
</div>
<div class="col-xs-12 col-sm-6 col-lg-6">
<?= $form->field($model, 'per_day')->textInput(['maxlength' => 30,
'placeholder' => $model->getAttributeLabel('per_day')]) ?>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'reduced_amount')->textInput(['maxlength' => 30,
'placeholder' => $model->getAttributeLabel('reduced_amount')]) ?>
</div>
<h4 class="box-title text-aqua"><?php echo Yii::t('payroll', 'Total Amount'); ?></h4>
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'net_salary')->textInput(['maxlength' => 30,
'placeholder' => $model->getAttributeLabel('net_salary')]) ?>
</div>
<?php } ?>
它不工作sir.please看看爵士