我的JavaScript代碼不起作用:如何在窗體中使用javascript確認框,並且可以在其中使用jsp?
<script type="text/javascript">
function verify() {
var amount = document.getElementById("amount");
var commission = document.getElementById("commission");
var commissionPayed = parseFloat(amount) * parseFloat(commission);
msg = "Withdraw Amount: " + amount.value + "\n Commission payed: " + commissionPayed.value;
//all we have to do is return the return value of the confirm() method
return confirm(msg);
}
形式本身:
<form action="Controller" method="post" onSubmit="return verify()">
<h1>Withdraw</h1>
<input type="hidden" name="command" id="command" value="withdrawAction">
<input type="hidden" name="commission" id="commission" value="${commission}">
<p>Amount: <input type="text" name="amount" id="amount"/></p>
<input type="submit" name="name" value="Withdraw" onclick="confirmation()"/></p>
</form>
在消息我得到的commissionPayed爲undefiened值。我究竟做錯了什麼?
有沒有在腳本中使用JSP的方法,如${object}
?
我可以在JSP中完成整個計算嗎?
現在我得到NaN而不是calue – 2011-04-19 08:10:01
您是否輸入了有效數字文本框和隱藏的表單域? [它適用於我。](http://jsfiddle.net/dYA5N/1/)順便說一句,你可以檢查NaN([不是數字](http://en.wikipedia.org/wiki/) NaN))的值使用[isNaN函數](https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#isNaN_Function)。 – PleaseStand 2011-04-19 10:54:18