PHP代码中的计算不会发生

时间:2015-02-09 07:13:17

标签: javascript

这是我的代码的一部分,但计算不起作用 输入/更改数量或费率字段数量后,我想要amt = qty * rate

                    <script type="text/javascript" charset="utf-8">
                    function calcamt()
                        {   
                        var a = document.getElementById('txtqty').value;
                        var b = document.getElementById('txtrate').value;
                        document.getElementById('pamt').value=a*b;
                        }
                    </script>
                    <script type="text/javascript" charset="utf-8">
                    function calcvtaxamt() 
                        {   
                        var a = document.getElementById('txtamt').value;
                        var b = document.getElementById('txtvtaxperc').value;
                        document.getElementById('pvtaxamt').value=round(a*b*0.01,0);
                        }
                    </script>
                   <td align="right"><input type="text" maxlength="10" size="10" name="txtqty"  onkeyup="javascript:calcamt()" value="<?php echo $pqty; ?>"/>
                   <td align="right"><input type="text" maxlength="10" size="10" name="txtrate" onkeyup="javascript:calcamt()" value="<?php echo $prate; ?>"/>
                   <td align="right"><input type="text" maxlength="12" size="12" name="txtamt" disabled="disabled" value="<?php echo $pamt; ?>"/>

1 个答案:

答案 0 :(得分:-1)

你必须给你的数量和费率上课。同时删除onkeyup功能。如下所示,

<input type="text" class="qty" maxlength="10" size="10" name="txtqty" value="<?php echo $pqty; ?>"/>
<input type="text" class="rate" maxlength="10" size="10" name="txtrate" value="<?php echo $prate; ?>"/>

Then in javascript:

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$( ".qty, .rate" ).live('change',function() {
        calcamt();
    });
});
</script>

Also put your rest of javascript code to calculate amt.