• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to keep a button from submitting a form.

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 28344
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the HTML forum.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a <button> tag with a type of other than "submit".
 
Did you miss me? Did you miss this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic