How to attach parameters in JSP based form
Ive been having this problem for the past couple of months and if you help I would really appreciate it. Im not sure if its a general JSP Ques or its simple HTML.
Im using the <c:forEach> to loop around products from a database then displaying them (incl an "Add to basket" button per each product) as an html form using jsp. Each row display is obviously associated with a product ID (primary key from the database). Now what I want to happen is: If someone clicks on add to basket on a certain produck, I need that product ID # to be carried over to the next page. This is obviously easy if the initial output was just static but here its dynamic. Here is a small shot of what Im saying:
The code
=====================================================
<table>
<tr>
<td>Product ID</td>
<td>Product Name</td>
<td>Price</td>
<td>Quantity</td>
<td>Add to Basket</td>
</tr>
<c:forEach var="row" items="${databaseResult.rows}">
<tr>
<td>${row.dbProductId}</td>
<td>${row.dbProductNm}</td>
<td>${row.dbPrice}</td>
<td><input type="text" name="formQuantity" value="Show Full Details"/></td>
<td><input type="submit" name="formSubmit" value="Add to Basket"/></td>
</tr>
</c:forEach>
</table>
=====================================================
The above is the code. When I have 10 products displayed, the moment I click on the 6th "Add to Basket" link, all parameters "formQuantity" are carried over yet I only want one to be carried. Ive tried using <input type= "hidden" but the same case happens again.
PLEASE HELP>
[2242 byte] By [
piasonpa] at [2007-10-2 16:54:27]

><c:url only takes urls only and I cannot put a parameter value ?
You are wrong sir.
><c:forEach var="row" items="${databaseResult.rows}">
<c:url value="/addToBasketServlet">
<c:param name="productId" value="${row.dbProductId}
</c:url>
</c:forEach>
">
Hie. Thanks for that reply but Ive just noticed that as much as I can attach parameters to certain variables, I still cant attach a parameter from a input text type of drop down menu.
What I mean is, the drop down menu general gets enclosed in a form but if Im to use the <c:url> tag for the other variables, that means there will be a conflict of the form action and the <c:url action>
drop down menu? where did theat come from?
You're not making much sense.
Basically you have to only pass the id of the line that you clicked on.
The easiest way to do that is with a link you click on.
If you can pass all the info you need in a URL with parameters, do that.
If you need to submit the entire form, then have a javascript onclick event that sets a hidden field for the value, and then submits the form.
Sorry, its me who wasnt clear. I never double checked my question. Ive re-pasted the previous code below with some slight changes: If you look at the code, you will see that when someone clicks on add to basket, the <c:param> will carry the productID through the url: '/confect/confectioneryV2.jsp' invoked by the <c:url> tag.
Now, if I need to carry the typed in quantity e.g a user types in 5 for the quantity, how will I make that to be carried over to the same url above. In general I know you use a form but in this case, this will conflict with the <c:url> link for the add to basket. What I mean is, the <c:url> tag has the above url while a form might have a diffferent url enclosed in its action command.
(I WANT TO AVOID USING JAVASCRIPT AND STICK TO JSP AND HTML ONLY)
If I leave out the conflicting form, then the quantity will not be carried across to the same page where the productID within the <c:url> tag is being carried over to.
The same applies if I need to use a drop down menu instead of the text input.
PLEASE HELP
=====================================================
<table>
<tr>
<td>Product ID</td>
<td>Product Name</td>
<td>Price</td>
<td>Quantity</td>
<td>Add to Basket</td>
</tr>
<c:forEach var="row" items="${databaseResult.rows}">
<tr>
<td>${row.dbProductId}</td>
<td>${row.dbProductNm}</td>
<td>${row.dbPrice}</td>
<td><input type="text" name= "formQuantity" value= "0"/><td>
<td><a href= "<c:url value= '/confect/confectioneryV2.jsp'>
<c:param name='productId' value='${row.nameId}'/>
</c:url>"
> Add to Basket </a>>
</td>
</tr>
</c:forEach>
</table>
=====================================================