File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to keep a button from submitting a form. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to keep a button from submitting a form." Watch "How to keep a button from submitting a form." New topic
Author

How to keep a button from submitting a form.

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
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

Joined: Aug 22, 2005
Posts: 76
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
Bartender

Joined: Oct 14, 2005
Posts: 18129
    
    8

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

Joined: Jan 10, 2002
Posts: 60055
    
  65

Moved to the HTML forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60055
    
  65

Use a <button> tag with a type of other than "submit".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to keep a button from submitting a form.
 
Similar Threads
I know what to do but don't know how to implement it..
Submit Methods pulling same data
submitting the invoice twice when submitt button is clicked
Pass radio button to servlet
Multiple Submit button in one jsp