传递给php表单时javascript动态变量的未定义索引

时间:2012-09-09 14:30:41

标签: php javascript html variables

<form action="testing.php" method="POST" id="addreciept" name="addreciept">
Unit<input name="unit1" type="text" id="unit1" size="17" onkeyup="calc()"   value="0"/>
Rate<input name="rate1" type="text" id="rate1" size="17" value="0" onkeyup="calc()"  />
Amount<input name="amount1" type="text" id="amount1" size="17"  disabled="true"   />
Total Amount: <input type="text" name="totalamount" id="totalamount" disabled="true"   value=""> 
Amount Paid: <input type="text" name="amount_paid" id="amount_paid" onkeyup="calc_balance()" />
Balance: <input type="text" name="balance" id="balance" disabled="true"  value="0"> 
<center>
<input type="submit" value="Save " class="button" >
</center>
</form>

<script>
function calc()
{
unit=document.getElementById('unit1').value;
rate=document.getElementById('rate1').value;
amount=unit*rate;
document.getElementById('amount1').value=amount;
total_amount=document.getElementById('amount1').value;
document.getElementById('totalamount').value=total_amount;
}
function calc_balance()
{
tota_amount=document.getElementById('totalamount').value;
paid_amount=document.getElementById('amount_paid').value;
document.getElementById('balance').value=tota_amount-paid_amount;
}
</script>

我最近测试了在网上发布的脚本,它可以工作,但我想我做错了什么:'(我被严重困在其中,因为动态变量,如amount1,totalamount和amp; balance导致undefined错误指数金额等等

plz弄明白:(

php只是简单的&gt;&gt;

<?php
echo $_POST['unit1'];
echo $_POST['rate1'];
echo $_POST['amount1'];
?>

1 个答案:

答案 0 :(得分:2)

禁用时,不会提交

表单元素(禁用amount1,totalamount和balance)

使用readonly-attribute