YoruichiKun
06-17-2009, 10:45 AM
Hi
I will try to explain this as best I can!
I'm trying to implement a shopping cart, as an example:
A buyer can search the store for clothes, and the shopping cart will be updated everytime with the items he has chosen. When the cart is displayed, each row shows an item, whereas each column show a colour represented by a checkbox, allowing the buyer to check what coloured item he wants. A remove button is placed at the end of each row so the buyer can remove any item he wants when the cart is displayed. Under the table, is a Pay button which forwards to another form displaying the final pricings of the checked items.
<table width="75%" border="1" cellspacing="0" cellpadding="0" class="MainBackground">
<tr>
<span class="Title"><b>Available Items </b></span>
</tr>
<tr>
<td width="30%" ><span class="Title"> Item Name</span></td>
<td> <span class="Title"> blue </td>
<td> <span class="Title"> white </td>
<td> <span class="Title"> red </td>
<td> <span class="Title"> black </td>
</tr>
<% ArrayList<ShoppingCartItem>
itemarr=theCart.getItems();
%>
<!-- iterate on shopping cart and display by one row per item -->
<% if (itemarr.size()>0)
{
for (int i=0; i< itemarr.size(); i++){
String item=itemarr.get(i).itemName;
%>
<tr>
<form>
<td width=30% ><span class="Title"></span></td>
<td> <input type="checkbox" name="<%= item %>"value="blue" id="1">
</td>
<td> <input type="checkbox" name="<%= item %>" value="white" id="1">
</td>
<td> <input type="checkbox" name="<%= item %>" value="red" id="1">
</td>
<td> <input type="checkbox" name="<%= item %>" value="black" id="1">
</td>
<td> <input type="submit" value="Remove" width="65" height="28" border="0" onclick="this.form.action='removeitem.jsp'">
</td>
<input type=hidden name="dname" value="<%=item%>">
<input type="Submit" value="Proceed to Shopping Cart" width="65" height="28" border="0" onclick="this.form.action='checkout.jsp'">
</form>
</tr>
<%} %>
<%}
%>
</table>
I'm using a for loop to iterate through the cart with already existing items, and adding the results of the search. The problem I am having is between the two button types. Both buttons need input from the forms, and I'm kind of lost on how to do this. The remove button needs to know which item needs to be removed, and the Pay button needs to know which colors have been checked. It's really quite a mess... so any help on how i can fix this dilemma would be much appreciated.
I will try to explain this as best I can!
I'm trying to implement a shopping cart, as an example:
A buyer can search the store for clothes, and the shopping cart will be updated everytime with the items he has chosen. When the cart is displayed, each row shows an item, whereas each column show a colour represented by a checkbox, allowing the buyer to check what coloured item he wants. A remove button is placed at the end of each row so the buyer can remove any item he wants when the cart is displayed. Under the table, is a Pay button which forwards to another form displaying the final pricings of the checked items.
<table width="75%" border="1" cellspacing="0" cellpadding="0" class="MainBackground">
<tr>
<span class="Title"><b>Available Items </b></span>
</tr>
<tr>
<td width="30%" ><span class="Title"> Item Name</span></td>
<td> <span class="Title"> blue </td>
<td> <span class="Title"> white </td>
<td> <span class="Title"> red </td>
<td> <span class="Title"> black </td>
</tr>
<% ArrayList<ShoppingCartItem>
itemarr=theCart.getItems();
%>
<!-- iterate on shopping cart and display by one row per item -->
<% if (itemarr.size()>0)
{
for (int i=0; i< itemarr.size(); i++){
String item=itemarr.get(i).itemName;
%>
<tr>
<form>
<td width=30% ><span class="Title"></span></td>
<td> <input type="checkbox" name="<%= item %>"value="blue" id="1">
</td>
<td> <input type="checkbox" name="<%= item %>" value="white" id="1">
</td>
<td> <input type="checkbox" name="<%= item %>" value="red" id="1">
</td>
<td> <input type="checkbox" name="<%= item %>" value="black" id="1">
</td>
<td> <input type="submit" value="Remove" width="65" height="28" border="0" onclick="this.form.action='removeitem.jsp'">
</td>
<input type=hidden name="dname" value="<%=item%>">
<input type="Submit" value="Proceed to Shopping Cart" width="65" height="28" border="0" onclick="this.form.action='checkout.jsp'">
</form>
</tr>
<%} %>
<%}
%>
</table>
I'm using a for loop to iterate through the cart with already existing items, and adding the results of the search. The problem I am having is between the two button types. Both buttons need input from the forms, and I'm kind of lost on how to do this. The remove button needs to know which item needs to be removed, and the Pay button needs to know which colors have been checked. It's really quite a mess... so any help on how i can fix this dilemma would be much appreciated.