gpt4 book ai didi

php - 传递到 php 表单时 JavaScript 动态变量上的未定义索引

转载 作者:行者123 更新时间:2023-12-02 19:22:53 25 4
gpt4 key购买 nike

<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 和balance 这样的动态变量导致了未定义索引的错误金额1等

请弄清楚:(

php 很简单>>

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

最佳答案

表单元素禁用时不会提交(amount1、total amount、balance禁用)

改用只读属性

关于php - 传递到 php 表单时 JavaScript 动态变量上的未定义索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12339945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com