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 getting id, not value from form element 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 "getting id, not value from form element" Watch "getting id, not value from form element" New topic
Author

getting id, not value from form element

Bill Brasskey
Ranch Hand

Joined: Jun 01, 2004
Posts: 47
I have a page that pulls from db, and corresponding to each record, I have two buttons (one for edit, one for report).
On the edit page, I need to know which record the button pressed corresponds to, so I can pull the record from the db. Problem is, all buttons have the same "value". If I use request.getParameter, I'm only going
to get the value, when what I need is the "id". I don't know how this is done. Any advice will be much appreciated!

input name="Submit" type="submit" class="buttonNeutral" **id="<%=goID[i]%>" value="Edit"

I'm wanting to know how to get the "id" value on another jsp, not the "value" value
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

Bill,
Create a hidden text field in your from with the value from your array. Since you will know the name you assigned to the hidden field, you will be able to get the value easily.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
You could just use the name attribute of the button - it does not have to be Submit.
The existance of a parameter with that name - as opposed to the names of the other buttons - will be sufficient.
Of course, hidden values are more flexible because you can have lots of them.
Bill
Sutham Rojanusorn
Greenhorn

Joined: Jul 10, 2004
Posts: 4
just adding some hidden field to your form

<form>
<input type="hidden" name="actionType" value="<%=goID[i]%>">
<input name="Submit" type="submit" class="buttonNeutral" **id="<%=goID[i]%>" value="Edit">
</form>
M. Gagnon
Ranch Hand

Joined: Feb 18, 2004
Posts: 68
I used a hyperlink in a similar situation instead of buttons:

<a href="recordDetailPage.jsp?recordID=<%=idsArr[i]%>">Detail Page</a>

Of course, if there are other form fields you want to submit, you'll have to append the name/value pairs to the query string above.

On the other hand, if you're set on using buttons . . .

If you use a separate hidden field for each record, they will all be submitted with the form unless you have a separate form for each button/hidden field pair (which seems like a tedious solution). If you use only one hidden field, you could set the id value with some client-side javascript. Define a javascript method to set the value parameter of the hidden field that's called in the onclick event of all the buttons.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: getting id, not value from form element
 
Similar Threads
Radio button value with submit
Building JSP pages and link to MySQL table
validation particular fields for different actions in a single page
how to get record ID??
Display all Users Detail on JSP page when we Loged in through ADMIN