• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to keep a button from submitting a form.

 
Fritz Largosa
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a form with two Submit buttons. Is it possible to only have one of the buttons trigger the action="Servlet", while the other does not. What I am trying to do is have only one button submit the form while the rest run methods which change my html/jsp front-end.

I cannot figure out how to keep a button from submitting a form. I only want one of the buttons to submit the form not all of them. If there is a way around this please let me know.

--------------------My code ---------------------------
<form action="Servlet" method="get">

<input type="submit" name="Submit" value="Submit">
<%
if(request.getParameter("Submit") != null){.a dynamic change occurs here..}
%>

<input type="submit" name="Submit2" value="Submit">
</form>
 
Anjana Ravindran
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can make another button as type "button" itself so that it wont act as submit button.

eg; input type="submit" ....
u can change it as

input type="button"...

If you also want to submit the form to submit using this button of type 'button', u can write some javascript which calls on clicking this button

fnSubmitForm() {
form.submit();
}

hope this helps. reply me if u have any questions.
 
Paul Clapham
Sheriff
Posts: 21550
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to prevent a button from submitting a form is to not put it between the <form> and </form> tags.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the HTML forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a <button> tag with a type of other than "submit".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic