• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting id, not value from form element

 
Bill Brasskey
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34656
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic