473,545 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating a Total Price in a Form

3 New Member
I am pretty new at doing web development. I can make simple pages, but recently received a request from a small limo business I do web development for.
We are currently working on a reservation form online for customers to fill out personal info, event details, and payment options. In the form we ask the customer to select what limo they want in addition to how many hours they want the limo for.
The problem I am running into is getting a total price to generate based on these two fields that the customer selects.

The limo type field is a drop down list:
Expand|Select|Wrap|Line Numbers
  1. <select name="Car">
  2.      <option value="None Selected">-----</option>
  3.      <option value="2007 Wave Limo">2007 Wave Limo</option>
  4.      <option value="Standard Wave Limo">Wave Limo</option>
  5.      <option value="Escalade Limo">Escalade Limo</option>
  6.      <option value="Sedan-Black">Sedan - Black</option>
  7.      <option value="Sedan White">Sedan - White</option>
  8. </select>
The Hours field is a drop down list as well.
Expand|Select|Wrap|Line Numbers
  1. <select name="Hours">
  2.      <option value="3">3 Hours (minimum)</option>
  3.      <option value="4">4 Hours</option>
  4.      <option value="5">5 Hours</option>
  5.      <option value="6">6 Hours</option>
  6. </select>
What we thought we could do was use a javascript code to designate a Rate variable based on the limo type the customer chose, something like:

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. if (document.form1.elements[0].Car=='2007 Wave Limo'){
  3.     Rate='70';}
  4. else if (document.form1.elements[0].Car=='Standard Wave Limo'){
  5.     Rate='50';}

We then wanted to multiply the Rate variable to the Hours variable and display the total price to the users. We just don't know how to write the code to do it.
We got as far as attempting to do a document.write statement to attempt this.

Expand|Select|Wrap|Line Numbers
  1. document.form1.elements[0].Cost=(Rate*document.form1.Hours)
  3. document.write(Cost);
We are currently hosted by GoDaddy on a Linux based platform and do not have a database connected to the site at all. All the variables we are attempting to use online and we are not 100% sure if this can even be done.

If anyone can see what we might be doing wrong or has a better way to accomplish this it would be greatly appretiated!

Thank you!
Mar 13 '07 #1
4 2290
27 New Member
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <script type="text/javascript">
  4.     window.onload=setTotal;
  5.     function setTotal(){
  6.         var price  = window.document.getElementById('price').value;
  7.         var time   = window.document.getElementById('time').value;
  8.         var result = window.document.getElementById('total'); 
  10.         result.value = price * time;
  11.     }
  12.     </script>
  13.   </head>
  14.   <body>
  15.     <select id="price" onchange="setTotal();">
  16.       <option value="10.50">Some Limo</option>
  17.       <option value="15.50">Other Limo</option>
  18.       <option value="11.50">Yet another limo</option>
  19.     </select>
  20.     <br />
  21.     <select id="time" onchange="setTotal();">
  22.       <option value="1">1 hour</option>
  23.       <option value="2">2 hours</option>
  24.       <option value="3">3 hours</option>
  25.     </select>
  26.     <br />
  27.     <input id="total" type="text" />
  28.   </body>
  29. </html>
simiplified, of course, hope that gets you on your way.
Mar 13 '07 #2
3 New Member
Thank you this worked like a charm!

One other question, is there a way to turn that total text field into a non-editable field?

We tested changing the generated 'total' value in the form and it keeps the value we changed it to.

For example, if the user selects Limo 1 for 3 Hours and the total field generates $200.00, the user can delete the $200.00 value and type in $30.00, which will be submitted in the form instead of the $200.00 it should be.

We were going down the lines of turning the 'total' text field into a hidden field, and then using a document.write script to display the value on the screen so the customer cannot change the value.

I'm probably totally off, but this is what I have:
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="total"><br>
  2. document.write(window.document.getElementById('total');)
If you know of a better way to do this, please let me know. Thank you!
Mar 20 '07 #3
224 New Member
hi there... all you have to do is make the text field readonly:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="total" readonly>
you could also make it disabled like this:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="total" disabled="disabled">
the disabled function reduces the text's opacity or make the text field grayed-out (depending on what browser you're using)... i would suggest using the readonly function... this is purely an HTML issue as no javascript is required for your text fields to be readonly...

note also, that the disabled function on select menu options only works in firefox (it's not cross-platform), so you shouldn't use the disabled function with select menus.
Mar 21 '07 #4
3 New Member
Wow, I didn't know about that readonly function.

Thanks everyone who helped!
Mar 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: flupke | last post by:
Hi, i create my GUIs mainly via wxGlade. However when you start of to program and want to do some rearranging to the gui, wxglade overwrites your file and you've got to put your own code back in. I think i can work around that (at least a bit) by making a second file that imports the gui generated by wxglade and make classes that extend...
by: Justin Lebar | last post by:
Sorry about the huge post, but I think this is the amount of information necessary for someone to help me with a good answer. I'm writing a statistical analysis program in ASP.net and MSSQL7 that analyzes data that I've collected from my business's webpage and the hits it's collecting from the various pay-per-click (PPC) engines. I've...
by: rick | last post by:
Can anyone help, I am try to create a simple form using a table, where a user can fill out quanty and price and have a total automatically calculated and inserted in another field. I stuck trying to figure out how expand this script to recalculate when rows are added or removed. My code so far. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML...
by: bin_P19 P | last post by:
the code i have got is as follows and now im stuck <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Shopping Cart</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="StyleSheet" href="css/style.css" type="text/css">
by: lyndsey | last post by:
i have a database to keep record of jobs in production, and on one of my forms, their is the control . in my form i have hundereds of records (jobs). is there a way i can create something in my record that will show me the grand total price of all the jobs in production. Thanks
by: Azurewrath | last post by:
I have a seemingly simple problem... I created a datagrid with 3 columns - quantity, unit price and line total. Line total is equal to quantity * unit price. I need the Line Total column to automatically compute (on the fly) as a user is editing the quantity or unit price columns and not when the focus leaves the quantity or unit price...
by: jimmyg123 | last post by:
Hi, I'm trying to do something similar. This is my javascript <script type='text/javascript'> function totalise(price,total) { var qty = window.document.getElementById('qty').value; var result = total; result.value = price * qty; }
by: lee123 | last post by:
hey all, i have made a order form with all the works. in vb 6 and in this form i have been trying to get a total of the items that a customer would have ordered. to make things make sense i have in my order form ( qty, product,unit price, and a total) there are 12 rows of these text boxes (1-44) i believe, any way on the bottom of the order form...
by: tonyhhisc | last post by:
This script calculates the total "listing_fee" based on the price that the user inputs into the "price" field. It works in Firefox but IE says "OBJECT NOT FOUND" please help me debug this, It's sooooo close! :) Thanks in advance for any help or guidance!! function calc() { tprice = document.sellticket.price.value; newprice = .05 *...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.