|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
i'm creating an order form for this small restaurant and it's gotta be datadriven, so i'm using access. i've got the menu items listed and the price and i've put in checkboxes next to each item for the customer to select which items they would like. i want to get the "checked" boxes and tell the database that's been selected and then through a query i want it to tell the customer what they have ordered(selected) and i'll be putting the results on another page
also, i've included how much of each item they would like (quantity), with a max of two characters, and i'd like to multiply the qty to the price and then tell the customer the total cost of the order. i know it's a lot to ask, but please! if anyone can help, i'm desperately in need of assistance, i'm only a learning student and need to get this done in the next couple of days =) thanks a million in advance |
|
#2
|
||||
|
||||
|
here is one way
ok i don't know if this is the cleanest way.... but it does work....
<% ichoice = Request.QueryString("choice") Select Case ichoice Case "order" %> <table border="0" cellpadding="0" cellspacing="5"> <% IF Request.Form("soup") = "on" Then subtotal1 = session("soupprice") * request.form("soupamount") Response.Write "<tr>" Response.Write "<td>" Response.Write "Soup" Response.Write "</td>" Response.Write "<td> " Response.Write "$" Response.Write formatNumber(subtotal1, 2) Response.Write "</td>" Response.Write "</tr>" End IF IF Request.Form("steak") = "on" Then subtotal2 = session("steakprice") * request.form("steakamount") Response.Write "<tr>" Response.Write "<td>" Response.Write "Steak" Response.Write "</td>" Response.Write "<td> " Response.Write "$" Response.Write formatNumber(subtotal2, 2) Response.Write "</td>" Response.Write "</tr>" End IF IF Request.Form("burger") = "on" Then subtotal3 = session("burgerprice") * request.form("burgeramount") Response.Write "<tr>" Response.Write "<td>" Response.Write "Burger" Response.Write "</td>" Response.Write "<td> " Response.Write "$" Response.Write formatNumber(subtotal3, 2) Response.Write "</td>" Response.Write "</tr>" End IF total = subtotal1 + subtotal2 + subtotal3 totalformated = formatNumber(total, 2) %> <tr> <td colspan="2">Total = $ <%=totalformated%></td> </tr> </table> <% Case Else session("soupprice") = "3.50" session("steakprice") = "15.78" session("burgerprice") = "5.98" %> <form action="checkboxes.asp?choice=order" method="post"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td><input type="Checkbox" name="soup"></td> <td Rowspan="3"> </td> <td><input type="Text" name="soupamount" size="2" maxlength="2"></td> <td Rowspan="3"> </td> <td>soup</td> <td Rowspan="3"> </td> <td>$ <%=session("soupprice")%></td> </tr> <tr> <td><input type="Checkbox" name="steak"></td> <td><input type="Text" name="steakamount" size="2" maxlength="2"></td> <td>steak</td> <td>$ <%=session("steakprice")%></td> </tr> <tr> <td><input type="Checkbox" name="burger"></td> <td><input type="Text" name="burgeramount" size="2" maxlength="2"></td> <td>burger</td> <td>$ <%=session("burgerprice")%></td> </tr> <tr> <td colspan="7"><br><input type="Submit" value="Submit"></td> </tr> </table> </form> <%End Select%> |
|
#3
|
|||
|
|||
|
i'm guessing you're getting all the records from the menu list table then looping through the recordset (in that loop is the code to put a checkbox on the page).
if all the checkboxes have the same name and the value for each checkbox is the item's id from the table then when you submit the form you'll get a comma-seperated list of all the values (only for those checkboxes which were checked) so let's say you've got two checkboxes, both named "orderList", checkbox A has the value of "1", checkbox B has the value of "2". if both are checked then submitted then either from the QueryString or Form collection you can get "orderList". when you retrieve it the value will be "1,2" you can then use the vbscript function Split() to split the list into an array. orderList = request.form("orderList") orderArray = Split(orderList, ",") 'split at comma character for i = lbound(orderArray) to ubound(orderArray) 'code to retrieve that items name,price and do any math from access db next to make the qty boxes work name the qty text boxes with the item's id. so checkbox A with it's value of 1 would have an accompanying text box for qty whos name is "1" then as you itterate through the array you could do request.form(orderArray(i)) heh, i'm not great at explaining things so if you'd like me to clear anything up i'd be glad to do so. you can test the request.form(orderArray(i)) idea with this code: <% x = Split(request.querystring("c"), ",") for i = lbound(x) to ubound(x) y = request.querystring(x(i)) response.write y & "<br>" & vbCrLf next %> then in the address bar of your browser: whatever_file.asp?c=4,5,7&4=d&5=e&7=z the output: d e z i'd be glad to give you sample code for your project that's much clearer and formatted well (if you'd like) - just email me or leave a reply here. -- justin |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > URGENT ASSISTANCE: Checkedboxes to access |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|