Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old January 11th, 2007, 04:00 PM
Authorized User
Join Date: Nov 2006
Location: St James, Manitoba, Canada.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Applying discount

I am writing a script for school and the script involves 3 dropdown lists of products. If a certain product is selected, say a "canon printer" then there would be no tax on this item but tax on the rest. What would be the best way to do this?

Here is some code:

<td colspan=4>

<select name="s1" onChange="which_prt()">
<option value="none" selected></option>
<option value="99.01">Epson Stylus C88 </option>
<option value="38.05">Canon Pixma IP1600</option>
<option value="957.11">EPSON STYLUS PHOTO 2200</option>

<input type="text" name="prt_qty" onChange="totalup_prt()"/>

<input type="text" name="prt_price" disabled/>

<input type="text" name="prt_total" disabled/>


function which_prt()
for (i=0;i<document.form1.s1.length;i++)
        if (document.form1.s1.value=="none")
            tmp_total_ord=(parseFloat(tmp_total_ord.toFixed(2) )-parseFloat(tmp_prt_total.toFixed(2)))


function totalup_prt()
document.form1.prt_total.value=("$"+tmp_prt_total. toFixed(2))
document.form1.prt_total.value=document.form1.prt_ total.value

Reply With Quote
  #2 (permalink)  
Old January 11th, 2007, 04:14 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons

Combine the values of your other 2 dropdowns add the effective tax rate then add in the value of your none taxed items so something like:

function calculate{
var total;
var taxRate = 6.5;
var taxTotal;

total = (parseFloat(document.form1.selectbox1.options[document.form1.selectbox1.selectedIndex].value) + parseFloat(document.form1.selectbox2.options[document.form1.selectbox2.selectedIndex].value));

taxTotal = total * taxRate;
total = total + taxTotal;

total = total + parseFloat(document.form1.selectbox2.options[document.form1.selectbox2.selectedIndex].value);

Of course you will have to deal with NaN values and such but that is how I would do it (more or less)

I will only tell you how to do it, not do it for you.††
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Applying CSS to tables andyhague CSS Cascading Style Sheets 4 April 5th, 2006 05:30 AM
Discount For P2P Members? anand_thakur Forum and Wrox.com Feedback 0 January 28th, 2005 08:05 AM
mysql discount table hosefo81 PHP Databases 0 December 12th, 2003 09:58 PM
Discount dannomite Wrox Book Feedback 3 June 5th, 2003 10:09 AM

All times are GMT -4. The time now is 11:03 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.