Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML表单字段在另一个字段更改时更新_Javascript_Forms_Input - Fatal编程技术网

Javascript HTML表单字段在另一个字段更改时更新

Javascript HTML表单字段在另一个字段更改时更新,javascript,forms,input,Javascript,Forms,Input,我有一个表单,当用户离开每个字段时,它会根据表单上输入的字段值更新总计。 这很好,但我还想更新其中一个输入字段,它是另一个字段的百分比 我的js中有 var theForm = document.forms[frm]; var eTotal = theForm.elements["Total"]; var ePremium = theForm.elements["Premium"]; if (eTotal.value > 0) { var PremAmount = parseFlo

我有一个表单,当用户离开每个字段时,它会根据表单上输入的字段值更新总计。 这很好,但我还想更新其中一个输入字段,它是另一个字段的百分比

我的js中有

var theForm = document.forms[frm];
var eTotal = theForm.elements["Total"];
var ePremium = theForm.elements["Premium"];
if (eTotal.value > 0) {
    var PremAmount = parseFloat(eTotal.value * ePremium.value / 100);
}
var divobj = document.getElementById('PremAmount');
divobj.innerHTML = PremAmount.toFixed(2);
这叫做

onblur="addPrem('totals')"
MySQL表中totals字段的原始值是770.00 我的php脚本生成以下html

<input name="PremAmount" tabindex="1" class="ent" id="PremAmount" size="2" value="77.00">

当我将总数更改为888.00时,我得到以下结果

<input name="PremAmount" tabindex="1" class="ent" id="PremAmount" size="2" value="77.00">88.80</input>
88.80
所以它看起来像是在工作,但是写了一个div而不是字段本身


有人能帮我吗请不要设置
innerHTML
,设置

var theForm = document.forms[frm];
var eTotal = theForm.elements["Total"];
var ePremium = theForm.elements["Premium"];
if (eTotal.value > 0) {
    var PremAmount = parseFloat(eTotal.value * ePremium.value / 100);
}
var divobj = document.getElementById('PremAmount');
divobj.value = PremAmount.toFixed(2);