javascript - how to invoke a jsp method onclickon form submit - Stack Overflow

I have a jsp page with this code:<script type="textjavascript">function getWithdrawAm

I have a jsp page with this code:

<script type="text/javascript">
function getWithdrawAmmount()
{
var withdraw=document.forms["WithdrawDeposit"]["AmountToWithdraw"].value;
document.getElementById('hidden').type = withdraw;
}
</script>

<form method="POST" name="WithdrawDeposit" onsubmit="getWithdrawAmmount()">
<table>
<tr><td><input type="text" size=5 name="AmountToWithdraw"></td>
<td><input type="button" value="Withdraw"></td></tr>
</table>
</form>
<input type="hidden" name="hidden" value="">

<% String AmountWithdraw = request.getParameter("hidden");  %>
<%!
public void Withdraw(){     
    int Amount = Integer.parseInt("AmountWithdraw");
Deposit deposit = new Deposit();
deposit.WithdrawMoney(AmountWithdraw);  
} %>

I need to activate the Withdraw() method on form submit and get the text input. the javascript hold the value inserted in 'hidden' and i can access it later. but i can't call to : <% Withdraw(); %> from inside javascript.

how can i call Withdraw() after button click?

10x

I have a jsp page with this code:

<script type="text/javascript">
function getWithdrawAmmount()
{
var withdraw=document.forms["WithdrawDeposit"]["AmountToWithdraw"].value;
document.getElementById('hidden').type = withdraw;
}
</script>

<form method="POST" name="WithdrawDeposit" onsubmit="getWithdrawAmmount()">
<table>
<tr><td><input type="text" size=5 name="AmountToWithdraw"></td>
<td><input type="button" value="Withdraw"></td></tr>
</table>
</form>
<input type="hidden" name="hidden" value="">

<% String AmountWithdraw = request.getParameter("hidden");  %>
<%!
public void Withdraw(){     
    int Amount = Integer.parseInt("AmountWithdraw");
Deposit deposit = new Deposit();
deposit.WithdrawMoney(AmountWithdraw);  
} %>

I need to activate the Withdraw() method on form submit and get the text input. the javascript hold the value inserted in 'hidden' and i can access it later. but i can't call to : <% Withdraw(); %> from inside javascript.

how can i call Withdraw() after button click?

10x

Share Improve this question edited May 3, 2012 at 19:09 WordToTheWise asked May 3, 2012 at 19:00 WordToTheWiseWordToTheWise 932 gold badges2 silver badges7 bronze badges 5
  • simply adding onClick="Withdraw();" in the input element should be enough. – Denys Séguret Commented May 3, 2012 at 19:02
  • 2 @dystroy — It is server side code, so no, that shouldn't work. – Quentin Commented May 3, 2012 at 19:13
  • doesn't work. starting to wonder if it's even possible.. – WordToTheWise Commented May 3, 2012 at 19:21
  • I don't understand the problem. Do you want to call the browser side function of the server side's one ? My ment was for calling the browser side's one. – Denys Séguret Commented May 3, 2012 at 19:23
  • server side function.. the problem is that i can't call the method Withdraw() on form submit. – WordToTheWise Commented May 3, 2012 at 19:30
Add a ment  | 

1 Answer 1

Reset to default 3

First off your line of code has issues

document.getElementById('hidden').type = withdraw;

It is looking for an element with an id of hidden. Not a name, an id. So add an id to the element you are referencing.

Second you are setting a type. Don't you want to set the value?

So the HTML would look like

<input type="hidden" name="hidden" id="hidden" value="" />

and the JavaScript would be

document.getElementById('hidden').value = withdraw;

Now if you want to call a function on the server, you either need to post back the form or make an Ajax call.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744108511a4558840.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信