0
<html><head>
<script language="JavaScript">
function update()
{
confirm("Are you sure?(Yes/No)");
document.forms[0].submit();
}
</script></head>
<body>
<form name="form1" method="post" action="controller/servlet">
<input type="submit" name="event" value="Add">
<input type="button" name="event" value="Update" onClick="update();">
</form>
</body>
</html>

here, on the click of both buttons "Add" and "Update",the control should go to the servlet.While clicking Update, the script runs and then the control transfers to servlet. But the name of the button Update is not read. What should be done so that the button value will be read in the servlet and the corresponding action takes place.
please help..

2
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by javaAddict
0

First of all we need to see the code at the servlet.
Second, you can have a hidden parameter in the jsp and the user clicks update to change its value:

<html><head>
<script language="JavaScript">
function update()
{
var r=confirm("Are you sure?");
if (r==true)
  {
document.form1.action.value='update';
document.forms[0].submit();
  }
else
  {
document.form1.action.value='';
  }
}
</script></head>
<body>
<form name="form1" method="post" action="controller/servlet">
...
...

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

</form>
</body>
</html>

Also check these 2 links:

http://www.w3schools.com/default.asp
http://www.w3schools.com/js/default.asp

0

code at the servlet is jus checking the value of the button and redirect to another page.

In servlet:

String event=request.getParameter("event");
if(event.equals("Update"))
{
response.sendRedirect("result.jsp");
}

Here when i print the value of the string event. Nothing is printed.

0

Have you tried my suggestion? I believe that you can't get the value from a "button", but I might be wrong.

0

what u said works!!!!! Is there any other more efficient of achieving this????

0

Have you tried using 2 different forms?

<form name="form1" method="post" action="controller/servlet">

  <input type="submit" name="event" value="Add">
</form>

<form name="form2" method="post" action="controller/servlet"
 onsubmit="return confirm("Are you sure?");" >

<input type="submit" name="event" value="Update" >
</form>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.