Chapter 24 Revisited: Dynamic Shipping Costs page 4

 by Tom Muck

If you were to look at the code for the dropdown list in the form, it would look like this:

<form name="form2" method="post" action="Checkout1.asp">
<select name="shippingMethod">
<%
While (NOT rsShipping.EOF)
%>
<option value="<%=(rsShipping.Fields.Item("ShippingMethodID").Value)%>" <%if (CStr(rsShipping.Fields.Item("ShippingMethodID").Value) = CStr(Request.Form("ShippingMethod"))) then Response.Write("SELECTED") : Response.Write("")%> ><%=(rsShipping.Fields.Item("ShippingMethod").Value)%></option>
<%
   rsShipping.MoveNext()
Wend
If (rsShipping.CursorType > 0) Then
   rsShipping.MoveFirst
Else
   rsShipping.Requery
End If
%>
</select>
</form>

7. The next step is to make the dropdown look a little nicer and display the actual price as well as the name by concatenating the ShippingCostPerPound field with the ShippingMethod field. We can do this right inside the script for the dynamic drop down list. Change this part:

<%=(rsShipping.Fields.Item("ShippingMethod").Value)%>

to this:

<%=(rsShipping.Fields.Item("ShippingMethod").Value)& " at " & FormatCurrency(rsShipping.Fields.Item("ShippingCostPerPound").Value)& " per pound" %>

The new code looks like this:

<form name="form2" method="post" action="Checkout1.asp">
<select name="shippingMethod">
<%
While (NOT rsShipping.EOF)
%>
<option value="<%=(rsShipping.Fields.Item("ShippingMethodID").Value)%>" <%if (CStr(rsShipping.Fields.Item("ShippingMethodID").Value) = CStr(Request.Form("ShippingMethod"))) then Response.Write("SELECTED") : Response.Write("")%> ><%=(rsShipping.Fields.Item("ShippingMethod").Value)& " at " & FormatCurrency(rsShipping.Fields.Item("ShippingCostPerPound").Value)& " per pound" %></option>
<%
   rsShipping.MoveNext()
Wend
If (rsShipping.CursorType > 0) Then
   rsShipping.MoveFirst
Else
   rsShipping.Requery
End If
%>
</select>
</form>

Now your dropdown list should look like this if you were to browse the page:

<<< Previous Next >>>