• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting id, not value from form element

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic