This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes 2 jsp buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "2 jsp buttons" Watch "2 jsp buttons" New topic

2 jsp buttons

Tracy Zoller

Joined: Dec 11, 2002
Posts: 4
I am outputting to the screen rows of data followed by 2 buttons, edit and delete. When the edit button is clicked the user should be asked if they want to edit the existing record or if they want to add a new record. If they choose to edit the existing record, the page will be forwarded to a screen where the user can edit data, if they choose to add a new record, the page will be forwarded to a screen where the user can enter a new record.
For the delete button, the user should be asked "Are you sure you want to delete this record?" If yes, record will be dumped into a deleted records table in the database. If no, keep focus on initial screen. Can anyone help me with this? I am desperate. Thanks in advance. My code is as follows:
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
remove underscore in ONCLICK:
<input name="Delete" type="button" id="Delete" value="Delete" on_click="if(confirm('Are you sure?')) this.form.submit();">
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

OK then.
Firstly, is it possible to make a part of the data a link? That way each record has a link that can be selected to act as the 'Edit' functionality. Then you no longer need the Edit button as such.

In theory you can manage the delete in the same way.
Obviously this will cause each operation to be executed as a HTTP GET method. If you need to post the data, have a (single) separate form with a dummy variable. When the user clicks the links, run some JavaScript to set the UID on the dummy variable (depending on the link selected) and submit the form.
The other way to manage delete functionality is to have a checkbox for each row and a single delete button. The delete button causes all of the selected items to be submitted to the delete servlet for processing.
Hope this helps.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15958

Also check out the Model 2 design approach. It's more complex than doing everything in JSPs but scales better.
You might even want to check out my Intro to Struts.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: 2 jsp buttons
Similar Threads
two dropdown menus
JSP error 500
2 jsp buttons
calling a java Script file into the Jsp
How to perform operations like insert,delete,add,move next etc in jsp page?