• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

cancel button issue

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a JSP page there are two buttons - submit and cancel.
The first buton- submit is on a form named 'f' along with other input fields.
The second button is outside form 'f'.

This works fine so far.

Now I introduce third button - save. The save button needs to submit the form f and hence it needs to be in form 'f'.

If all three buttons are put in a row in form 'f' with cancel button in middle (user requirement), then cancel button is going to be in form 'f'.

For cancel action (hitting cancel button), I don't want to submit the form.

How can I keep cancel button in middle but preventing form f being submitted on cancel action?
 
Marshal
Posts: 67388
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not even remotely a JSP issue.

Moved to the HTML forum.
 
Bear Bibeault
Marshal
Posts: 67388
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by jiju ka:

For cancel action (hitting cancel button), I don't want to submit the form.



Then don't make it a submit button.
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Then don't make it a submit button.


I am looking for a solution.

I need to have button for cancel. The server needs to do some action but the form need not be submitted.

The contents of the input fields in the form should not be transfered to the server. It is OK to execute the doGet or doPost method of the servlet.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The server needs to do some action but the form need not be submitted



Well the only way that you can talk with the server is to post the page back to it. That is normally done with a form submission.

Eric
 
Bear Bibeault
Marshal
Posts: 67388
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by jiju ka:
The server needs to do some action but the form need not be submitted.



Again, don't make the cancel button a submit button and it will not automatically submit the enclosing form.

In the onclick handler for the non-submit button you can use Ajax to talk back to the server, or you can submit another (perhaps invisible form) to talk back to the server without submitting the "main" form.
 
keep an eye out for scorpions and black widows. But the tiny ads are safe.
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic