Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determining which submit button is pressed and setting a hidden value 1

Status
Not open for further replies.

excession

Programmer
Joined
Sep 22, 2004
Messages
111
Location
GB
I have a for which contains a table of items. The last column has a button in each row called "Place Bid"

When I process the form how can I tell which of the "Place Bid" buttons was actually clicked?

I've been trying to use javascript to set a hidden value, but I've a novice with JS.

Any suggestions?

and example of my for:


<form name="bidding" method="post" action="PlaceBid.jsp">
<table width="200" border="1">
<tr>
<td>Item 1</td> <td> etc etc </td>

<td> <input type="submit" name="Submit" value="Place Bid"> </td>
</tr>
</table>
<input type="hidden" name="whichbutton" value="?">
<input type="hidden" name="by" value="<%=request.getParameter("by")%>">
</form>
 
Use an onclick handler on each of your submit buttons. This onclick event will trigger before the page is submitted, so you can set any hidden variables you need to at that time. Try something like this for your multiple submit buttons:
Code:
<form name="bidding" method="post" action="PlaceBid.jsp">
...
...
<input type="submit" name="Submit" value="Place Bid" onclick='document.forms["bidding"].elements["whichbutton"].value=1'>
...
<input type="submit" name="Submit" value="Place Bid" onclick='document.forms["bidding"].elements["whichbutton"].value=1'>
...
<input type="submit" name="Submit" value="Place Bid" onclick='document.forms["bidding"].elements["whichbutton"].value=1'>
...
<input type="hidden" name="whichbutton" value="?">
...
</form>

-kaht

Weaseling out of things is important to learn. It's what separates us from the animals... except the weasel. - Homer Simpson (no, I'm not Homer)
 
You are a genious! Worked a treat, Thank.
 
gah.... I made a typo in the post. The values were supposed to increment:

.value=1
.value=2
.value=3

But I'm sure you got the idea [lol]

-kaht

Weaseling out of things is important to learn. It's what separates us from the animals... except the weasel. - Homer Simpson (no, I'm not Homer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top