Jump to content

calculating total price


mckenzie

Recommended Posts

hello there jus wondering if anyone could help me on this problem i have. I've got a we page that displays 18 drop down boxes that show diferent items from a databse. when the items within the drop down boxes are clicked the price of the items appear next to them in the text boxes. i would like to put a quantity of items in and a total price that changes with every change of the form. how woul og go about doing this? this is my code:<html><Head><script> function Fn_Drd_Change(Combo, Text) {eval("document.forms(0)."+ Text +".value = document.forms(0)."+ Combo +".value"); }</script><%Dim connDim CmdPopulatefoodDim SQLdim FieldNamedim TableNameset Conn = Server.createobject("ADODB.Connection")conn.open "PROVIDER=Microsoft.jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("Project.mdb") & ";" Set rs = Server.CreateObject("ADODB.RecordSet")%><%Sub Fillcombo (TableName, name, price)SQL= "SELECT " & name & " , "& price&" FROM " & TableNamers.Open SQL, connIf Not rs.EOF Then Do While Not rs.EOF %> <Option value=<%= rs("price")%>><%= rs("name")%></Option> <% rs.MoveNext LoopEnd Ifrs.CloseEnd Sub%><body><table border="1"><tr><td><form method="POST" action="default.asp"><P><Select Name="Drd1" OnChange=" Fn_Drd_Change('Drd1','Txt1')"><% Call Fillcombo("BAKERYandCAKES", "name","price") %></Select><INPUT Name="Txt1" Value=""></p><P><Select Name="Drd2" OnChange=" Fn_Drd_Change('Drd2','Txt2')"><% Call Fillcombo("BEERCIDERALCOPOPS", "name","price") %></Select><INPUT Name="Txt2" Value=""></P><P><Select Name="Drd3" OnChange=" Fn_Drd_Change('Drd3','Txt3')"><% Call Fillcombo("BISCUITSSNACKSandSWEETS", "name","price") %></Select><INPUT Name="Txt3" Value=""></P><P><Select Name="Drd4" OnChange=" Fn_Drd_Change('Drd4','Txt4')"><% Call Fillcombo("BREAKFASTCEREALS", "name","price") %></Select><INPUT Name="Txt4" Value=""></P><P><Select Name="Drd5" OnChange=" Fn_Drd_Change('Drd5','Txt5')"><% Call Fillcombo("COOKINGINGREDIENTS", "name","price") %></Select><INPUT Name="Txt5" Value=""></P><P><Select Name="Drd6" OnChange=" Fn_Drd_Change('Drd6','Txt6')"><% Call Fillcombo("DAIRYEGGSandCHEESE", "name","price") %></Select><INPUT Name="Txt6" Value=""></P><P><Select Name="Drd7" OnChange=" Fn_Drd_Change('Drd7','Txt7')"><% Call Fillcombo("FRESHFRUIT", "name","price") %></Select><INPUT Name="Txt7" Value=""></P><P><Select Name="Drd8" OnChange=" Fn_Drd_Change('Drd8','Txt8')"><% Call Fillcombo("FROZENCHIPSandVEG", "name","price") %></Select><INPUT Name="Txt8" Value=""></P><P><Select Name="Drd9" OnChange=" Fn_Drd_Change('Drd9','Txt9')"><% Call Fillcombo("FROZENDESERTICECREAM", "name","price") %></Select><INPUT Name="Txt9" Value=""></P><P><Select Name="Drd10" OnChange=" Fn_Drd_Change('Drd10','Txt10')"><% Call Fillcombo("FROZENMEATFISHandPOULTRY", "name","price") %></Select><INPUT Name="Txt10" Value=""></P><P><Select Name="Drd11" OnChange=" Fn_Drd_Change('Drd11','Txt11')"><% Call Fillcombo("FROZENREADYMEALSPIZZA", "name","price") %></Select><INPUT Name="Txt11" Value=""></P><P><Select Name="Drd12" OnChange=" Fn_Drd_Change('Drd12','Txt12')"><% Call Fillcombo("MEATFISHandPOULTRY", "name","price") %></Select><INPUT Name="Txt12" Value=""></P><P><Select Name="Drd13" OnChange=" Fn_Drd_Change('Drd13','Txt13')"><% Call Fillcombo("READYMEALSandPIZZA", "name","price") %></Select><INPUT Name="Txt13" Value=""></P><P><Select Name="Drd14" OnChange=" Fn_Drd_Change('Drd14','Txt14')"><% Call Fillcombo("READYMEALSandPIZZA", "name","price") %></Select><INPUT Name="Txt14" Value=""></P><P><Select Name="Drd15" OnChange=" Fn_Drd_Change('Drd15','Txt15')"><% Call Fillcombo("SPIRITS", "name","price") %></Select><INPUT Name="Txt15" Value=""></P><P><Select Name="Drd16" OnChange=" Fn_Drd_Change('Drd16','Txt16')"><% Call Fillcombo("TINSPACKETSandJARS", "name","price") %></Select><INPUT Name="Txt16" Value=""></P><P><Select Name="Drd17" OnChange=" Fn_Drd_Change('Drd17','Txt17')"><% Call Fillcombo("VEGSALADSandDIPS", "name","price") %></Select><INPUT Name="Txt17" Value=""></P><P><Select Name="Drd18" OnChange=" Fn_Drd_Change('Drd18','Txt18')"><% Call Fillcombo("WINES", "name","price") %></Select><INPUT Name="Txt18" Value=""></P><input type="submit" value="Submit"></form></td></tr></table></body></html>thankyou

Link to comment
Share on other sites

You need to put another text box next to the price text box I would assume, and then put a total text box down at the bottom. You have a table in the code, but then everything is in only 1 cell in the table. Use <tr> and <td> to create rows and cells in the table, and put each product on one row. Put the different text boxes and dropdowns in the cells, and then you can put a quantity on the end.You need to add a javascript function that multiplies all the quantities by the prices, and adds them up to calculate total cost. Have that function execute whenever either a dropdown is changed or a quantity is changed. You will also want to disable the price text field so that the user can't change the value.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...