Calculating the price based on the difference of t

# Thread: Calculating the price based on the difference of t

1. Daphne Guest

## Calculating the price based on the difference of t

I have a problem for calculating the price for a product based on the difference of the date. Lets say I am a car rental company. I have a list box where the customer can select the type of car they want (The price of the car are different). Then I would like to have the price of that particular car to appear in a text boxt name price below that list box. How should I do this? After this, There are 3 list box namely Day, Month and year under the name of "date of pickup" and another 3 list box with the samething under the name of "date of return." Now, how am I going make the program take the date of return and minus the date of pickup to get the number of days that the customer wants to rent the car and then take that figure and times it with the price of the car and output that price in another text box with the name total price on the same page?

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Sounds like JavaScript problem...

...to me. 100% client side JavaScript, no ASP involved. Yes?<BR><BR>If so, you should read some of the better JS "help" sites and the JS reference materials.<BR><BR>But I&#039;ll try a tiny sample page for you and *hope* this isn&#039;t homework.<BR><BR><BR>******** CarPrice.html ***********<BR>&#060;HTML&#062;&#060;BODY&#062;<BR ><BR><BR>&#060;SCRIPT Language="JavaScript"&#062;<BR><BR>function calculate(frm)<BR>{<BR>&nbsp; &nbsp; var outDate = <BR>&nbsp; &nbsp; &nbsp; &nbsp; new Date( frm.OutYear.selectedIndex + 2001,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; frm.OutMonth.selectedIndex,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; frm.OutDay.selectedIndex + 1 );<BR>&nbsp; &nbsp; var inDate = <BR>&nbsp; &nbsp; &nbsp; &nbsp; new Date( frm.InYear.selectedIndex + 2001,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; frm.InMonth.selectedIndex,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; frm.InDay.selectedIndex + 1 );<BR>&nbsp; &nbsp; var diffMilliseconds = inDate.getTime() - outDate.getTime();<BR>&nbsp; &nbsp; var diffDays = diffMilliseconds / ( 1000 * 60 * 60 * 24 );<BR>&nbsp; &nbsp; frm.NumDays.value = diffDays;<BR>&nbsp; &nbsp; var price = diffDays * <BR>&nbsp; &nbsp; &nbsp; &nbsp; frm.CarCategory.options[frm.CarCategory.selectedIndex].value;<BR>&nbsp; &nbsp; var pretty = "\$" + price;<BR>&nbsp; &nbsp; frm.TotalPrice.value = pretty.substring(0,pretty.length-2) +<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "." + pretty.substring(pretty.length-2);<BR>}<BR><BR>&lt;/SCRIPT&#062;<BR><BR>&lt;FORM&#062;<BR><BR>Date out:<BR>&lt;Select Name=OutMonth&#062;<BR>&lt;OPTION&#062;Jan&nbsp; &nbsp; &lt;OPTION&#062;Feb &lt;OPTION&#062;Mar &lt;OPTION&#062;Apr &lt;OPTION&#062;May &lt;OPTION&#062;Jun <BR>&lt;OPTION&#062;Jul &lt;OPTION&#062;Aug &lt;OPTION&#062;Sep &lt;OPTION&#062;Oct &lt;OPTION&#062;Nov &lt;OPTION&#062;Dec<BR>&lt;/SELECT&#062;<BR>&lt;SELECT Name=OutDay&#062;<BR>&lt;OPTION&#062;1 &lt;OPTION&#062;2 &lt;OPTION&#062;3 &lt;OPTION&#062;4 &lt;OPTION&#062;5<BR>&lt;OPTION&#062;6 &lt;OPTION&#062;7 &lt;OPTION&#062;8 &lt;OPTION&#062;9 &lt;OPTION&#062;10<BR>&lt;OPTION&#062;11 &lt;OPTION&#062;12 &lt;OPTION&#062;13 &lt;OPTION&#062;14 &lt;OPTION&#062;15<BR>&lt;OPTION&#062;16 &lt;OPTION&#062;17 &lt;OPTION&#062;18 &lt;OPTION&#062;19 &lt;OPTION&#062;20<BR>&lt;OPTION&#062;21 &lt;OPTION&#062;22 &lt;OPTION&#062;23 &lt;OPTION&#062;24 &lt;OPTION&#062;25<BR>&lt;OPTION&#062;26 &lt;OPTION&#062;27 &lt;OPTION&#062;28 &lt;OPTION&#062;29 &lt;OPTION&#062;30<BR>&lt;OPTION&#062;31<BR>&lt ;/SELECT&#062;<BR>&lt;SELECT Name=OutYear&#062;<BR>&lt;OPTION&#062;2001 &lt;OPTION&#062;2002 &lt;OPTION&#062;2003<BR>&lt;/SELECT&#062;<BR>&lt;P&#062;<BR>Date in:<BR>&lt;Select Name=InMonth&#062;<BR>&lt;OPTION&#062;Jan&nbsp; &nbsp; &lt;OPTION&#062;Feb &lt;OPTION&#062;Mar &lt;OPTION&#062;Apr &lt;OPTION&#062;May &lt;OPTION&#062;Jun <BR>&lt;OPTION&#062;Jul &lt;OPTION&#062;Aug &lt;OPTION&#062;Sep &lt;OPTION&#062;Oct &lt;OPTION&#062;Nov &lt;OPTION&#062;Dec<BR>&lt;/SELECT&#062;<BR>&lt;SELECT Name=InDay&#062;<BR>&lt;OPTION&#062;1 &lt;OPTION&#062;2 &lt;OPTION&#062;3 &lt;OPTION&#062;4 &lt;OPTION&#062;5<BR>&lt;OPTION&#062;6 &lt;OPTION&#062;7 &lt;OPTION&#062;8 &lt;OPTION&#062;9 &lt;OPTION&#062;10<BR>&lt;OPTION&#062;11 &lt;OPTION&#062;12 &lt;OPTION&#062;13 &lt;OPTION&#062;14 &lt;OPTION&#062;15<BR>&lt;OPTION&#062;16 &lt;OPTION&#062;17 &lt;OPTION&#062;18 &lt;OPTION&#062;19 &lt;OPTION&#062;20<BR>&lt;OPTION&#062;21 &lt;OPTION&#062;22 &lt;OPTION&#062;23 &lt;OPTION&#062;24 &lt;OPTION&#062;25<BR>&lt;OPTION&#062;26 &lt;OPTION&#062;27 &lt;OPTION&#062;28 &lt;OPTION&#062;29 &lt;OPTION&#062;30<BR>&lt;OPTION&#062;31<BR>&lt ;/SELECT&#062;<BR>&lt;SELECT Name=InYear&#062;<BR>&lt;OPTION&#062;2001 &lt;OPTION&#062;2002 &lt;OPTION&#062;2003<BR>&lt;/SELECT&#062;<BR>&lt;P&#062;<BR><BR>Select a car category and per day price: <BR>&lt;SELECT Name=CarCategory&#062;<BR>&lt;OPTION Value="1995"&#062;Economy -- \$19.95<BR>&lt;OPTION Value="2295"&#062;Compact -- \$22.95<BR>&lt;OPTION Value="2595"&#062;Mid Size -- \$25.95<BR>&lt;OPTION Value="2995"&#062;Economy -- \$29.95<BR>&lt;/SELECT&#062;<BR>&lt;P&#062;<BR>&lt;Input Type=Button Name="Calc"<BR> Value="Click to calculate" onClick="calculate(this.form);"&#062;<BR>&lt;HR&#0 62;<BR>Total rental for <BR>&lt;INPUT Name="NumDays" Size=3 onFocus="this.form.Calc.focus();"&#062;<BR>days is<BR>&lt;INPUT Name="TotalPrice" Size=10 onFocus="this.form.Calc.focus();"&#062;.<BR>&lt;/FORM&#062;<BR><BR>&lt;/BODY&#062;&lt;/HTML&#062;<BR><BR><BR>

3. Daphne Guest

## Thank you!

Thank you for the answer you have given. I assure you that it is not homework. I am doing but some form of research on the various form of pricing on the net. I hope you will be able to give me more advice if I should encounter more difficulties on this particular form of pricing.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•