My JavaScript code doesn't work:
<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);
}
The form itself:
<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>
In the message I get the commissionPayed as undefiened value. What am I doing wrong?
Is there a way to use JSP inside the script such as ${object}
?
Can I do the entire calculation in JSP?