473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

help adding up dropdown options

Hello.

Let's say I have a dropdown in a form like this:

<SELECT NAME = "ShippingMethod">
<OPTION VALUE = "ptbship:Standard Ground Service" shipindex="1"
shipcost="9.00">Standard Ground Service ($9.00)</OPTION>
<OPTION VALUE = "ptbship:2 Day Express" shipindex="2" shipcost="20.00">2
Day Express ($20.00)</OPTION>
<OPTION VALUE = "ptbship:Next Day Express" shipindex="3" shipcost="45.00">
Next Day Express ($45.00)</OPTION>
</SELECT>

And let's say I also have a seperate subtotal figured out. For discussion
sake let's say I know it is already $50.

I need to do the following:

First I need to add the subtotal and the shipcost amount together. So in
this case the subtotal is 50.00 and someone selects option2 with a shipcost
of 20.00 so that would make 70.

Then I need to figure out tax on that new subtotal. Tax is 8.35% (.0835).

Finally I need to display it all like so:

Subtotal: $50.00
Shipping: $20.00 (in the case someone picked option 2 above)
Tax: $5.85 (rounded off to 2 decimal places)

Total: $72.85

Can someone help me with this? I've been fiddling with some stuff I found
on directdrive.com and other places but not getting any joy yet. Thanks
very much.
Apr 10 '07 #1
3 1927
Adam said the following on 4/10/2007 3:53 PM:
Hello.
<snip>
Can someone help me with this? I've been fiddling with some stuff I found
on directdrive.com and other places but not getting any joy yet. Thanks
very much.
Try reading the textbook and ask your instructor as it all reads as a
class assignment.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 10 '07 #2
Very helpful. And no it is not.

Hopefully that display of arrogance won't deter someone helpful from
posting.

Randy Webb <Hi************@aol.comwrote in
news:TL********************@giganews.com:
Adam said the following on 4/10/2007 3:53 PM:
>Hello.

<snip>
>Can someone help me with this? I've been fiddling with some stuff I
found on directdrive.com and other places but not getting any joy
yet. Thanks very much.

Try reading the textbook and ask your instructor as it all reads as a
class assignment.
Apr 10 '07 #3
Adam wrote:
Let's say I have a dropdown in a form like this:
[...]
And let's say I also have a seperate subtotal figured out.
For discussion sake let's say I know it is already $50.

I need to do the following:

First I need to add the subtotal and the shipcost amount
together. So in this case the subtotal is 50.00 and someone
selects option2 with a shipcost of 20.00 so that would make 70.

Then I need to figure out tax on that new subtotal. Tax is
8.35% (.0835).

Finally I need to display it all like so:

Subtotal: $50.00
Shipping: $20.00 (in the case someone picked option 2 above)
Tax: $5.85 (rounded off to 2 decimal places)
Total: $72.85
I wouldn't put the price in a XML-style 'shipcost' argument, but in
the value of the option.

<form>
<select name="S" size="1" onChange="do_calc()">
<option value="09.00§ptbship:Standard Ground Service">
Standard Ground Service ($9.00)</option>
<option value="20.00§ptbship:2 Day Express">
2 Day Express ($20.00)</option>
<option value="45.00§ptbship:Next Day Express">
Next Day Express ($45.00)</option>
</select>
</form>

<div id="displ">&nbsp;</div>

<script type="text/javascript">
var order = 50
var taxperc = 8.35
var f = document.forms[0].S

function do_calc() {
var sc = f.options[f.selectedIndex].value.split('§')
sc[0] = parseFloat(sc[0])
var tax = Math.round((order + sc[0]) * taxperc) / 100
var total = Math.round((order + sc[0] + tax) * 100) / 100
var summary = 'Subtotal: $' + order + '<br>'
summary += 'Shipping: $' + sc[0] + '<br>'
summary += 'Tax: $' + tax + '<br>'
summary += 'Total: $' + total
document.getElementById('displ').innerHTML = summary
}

do_calc()
</script>

Hope this helps,

--
Bart

Apr 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
2
by: Michael | last post by:
I want to have more population dropdown boxes (see below script) but it gives me an error on the line "for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options =...
3
by: Evan | last post by:
I have searched high and low and am posting this question in the hope that someone out there on the net can help me out. I am using a merge of ASP and JavaScript. My goal is to create 2 drop...
2
by: Ian | last post by:
Can anyone help me with a problem I have. What I need to be able to do is have the user presented with a single dropdown menu within a form using HTML <SELECT> and <OPTION>. Once they choose a...
6
by: Scott | last post by:
The code below appears to work on the following: MAC - Safari PC - IE PC - Opera But the addition of items to the dropdown (select2) does not function in: MAC – IE
2
by: Bruno Alexandre | last post by:
Hi guys, I'm using Javascript to dynamically add to a dropdown values like for ( i=0; i<tv.length; i++ ) { selectDDAvisCtrl.options = new Option(tv, tv); } and I use ...
13
by: pamelafluente | last post by:
Hello. I have written the following code (this code is on a control): Sub InitSomething() mSet(me.FindForm) End Sub Sub mSet(ByVal f As Control) For Each t As Control In f.Controls If...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.