gpt4 book ai didi

javascript - HTML 变量导致 CGI 文件出错

转载 作者:行者123 更新时间:2023-11-28 16:35:26 24 4
gpt4 key购买 nike

我在从 cgi 文件打印特定变量时遇到问题。我从我的网页收到这个名为 TotalCost 的变量,然后尝试打印它,但没有任何反应。所有其他变量都可以从网页成功接收并通过我的 cgi 文件打印在另一个网页上,除了这个。我已经检查了大小写敏感性,但这没有帮助

html 中的代码...

<tr>  <td colspan=3 padding=2><b> Total =  $ </b> <input type= "text" id="totalCost" disabled= true name= "totalCost" size ="5" maxlength="5" value= 0.00 /> <td> <tr>

计算成本函数

<script type= "text/javascript">

function computeCost(){

var apples= document.getElementById("appleQty").value;
var oranges=document.getElementById("orangeQty").value;
var bananas=document.getElementById("bananaQty").value;

var totCostTemp=0.69*apples + 0.59*oranges + 0.39*bananas;

document.getElementById("totalCost").value= totCostTemp;

}
</script>

在我使用 Perl 编写的 cgi 文件中,我以这种方式接收变量:

my ($appleQty, $orangeQty, $bananaQty, $user, $cardType, $c) = (param("appleQty"), param("orangeQty"), param("bananaQty"), param("user"), param("cardType"), param("totalCost"));

然后尝试以这种方式打印出来..

print header;
print start_html("Receipt"),
print h3("Fruit Store: Order Summary"),
table({-border => 2} ,caption("Your Receipt"),
Tr([th("Name:").td($user),th("Payment Method:").td($cardType),th("Fruit Type").td("Quantity"), th("Apple").td($appleQty), th("Oranges").td($orangeQty), th("Bananas").td($bananaQty), th("Total Cost:").td($c)]));
print end_html;

请注意...除totalCost 之外的所有变量均已正确打印。 TotalCost 根本没有打印在我的结果网页中...我认为这与我做了一些计算并且可能没有将其正确存储在 id 中有关。但我不知道如何解决这个问题..

感谢您的建议!

最佳答案

禁用的字段不会被发布。因此,您只需修改该字段以使其只读。喜欢:

<input type="text" id="totalCost" readonly="true" name="totalCost" size ="5" value="0.00" />

如果你不喜欢只读字段的颜色,你可以使用 CSS 来修改它,如下所示:

<style>
input[readonly=true] {
color:silver;
}
</style>
<小时/>

或者为了更好的 CSS 兼容性:

<style>
.disabled {
color:silver;
}
</style>

<input type="text" id="totalCost" readonly="true" name="totalCost" size ="5" value="0.00" class="disabled" />

您还可以使用隐藏字段,但不必更改当前代码。

关于javascript - HTML 变量导致 CGI 文件出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4247084/

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