<% Option Explicit %> <% dim action : action = getAction(Request.form) if action = "Update" then update Request.form elseif action = "Remove" then remove Request.form end if %> Untitled Document <% DisplayHeader "Shop" DisplayNavMenu "Shop" %>
<% if Main() = True then ' if the cart is not empty %> <% else %> <% end if %>

<% function Main() dim rs dim albumNumbers, quantities, i dim subTotal albumNumbers = GetCartItems() quantities = GetCartQuantities() if ubound(albumNumbers) = -1 then Response.write "Your shopping cart is empty." Main = False exit function end if Response.write "" & _ "Your shopping cart contains:" & _ "Quantity" & _ "" & _ " " set rs = GetAlbumsInfo(albumNumbers) subTotal = 0 ' displays albums in the order albums were chosen by user for i = 0 to ubound(albumNumbers) rs.filter = adFilterNone rs.filter = "AlbumNo=" & albumNumbers(i) subTotal = subTotal + (quantities(i) * rs("OurPrice")) displayAlbumInfo rs, quantities(i) Response.write " " next rs.close set rs = Nothing Response.write "
" & _ "Subtotal: " & formatCurrency(subTotal) & "" & _ " " Main = True end function %> <% sub displayAlbumInfo(rs, quantity) %> ">" border="0"> " style="font-style: italic"><%= rs("AlbumTitle") %>
"><%= rs("ArtistName") %>
Item #<%= rs("AlbumNo") %>
<%= formatCurrency(rs("OurPrice")) %> " size="2" maxlength="4" value="<%= quantity %>"> " src="images/buttons/remove.gif">
<% end sub %> <% ' req is Request.form function getAlbumNo(req) dim field for each field in req if inStr(field, "Add") then getAlbumNo = ExtractAlbumNoFromString(field) exit function end if next end function ' returns "Update", "Remove", or "" ' req is Request.form ' The proper format for the name of an image form field is as follows: ' for updating the cart, or ' (where XXXX is the album no.) for removing from the cart. function getAction(req) dim field if req.count = 0 then getAction = "" exit function end if for each field in req if inStr(field, "Remove") then getAction = "Remove" exit function end if next ' If the submitted form does not have a field named "Remove", then it is assumed the user clicked "Update" or pressed Return in a qty textbox. getAction = "Update" end function sub update(req) dim field for each field in req if inStr(field, "Update-") then UpdateCartItem ExtractAlbumNoFromString(field), req(field) ' req(field) is the quantity end if next end sub sub remove(req) dim field for each field in req if inStr(field, "Remove") then RemoveFromCart ExtractAlbumNoFromString(field) exit sub end if next end sub %>