help adding up dropdown options

A

Adam

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.
 
A

Adam

Very helpful. And no it is not.

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

Bart Van der Donck

Adam said:
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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top