Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 11th, 2007, 05:00 PM
Authorized User
 
Join Date: Nov 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Applying discount

Hi:
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:

HTML
<tr>
<td colspan=4>
<h3>Printers</h3>
</td>
</tr>

<tr>
<td>
<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>
</select>
</td>

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

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

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

</tr>



Javascript
function which_prt()
{
for (i=0;i<document.form1.s1.length;i++)
    {
    if(document.form1.s1[i].selected==true)
        {
        if (document.form1.s1.value=="none")
            {
            document.form1.prt_qty.value=""
            document.form1.prt_price.value=""
            document.form1.prt_total.value=""
            tmp_prt_qty=0
            tmp_prt_price=0
            tmp_total_ord=(parseFloat(tmp_total_ord.toFixed(2) )-parseFloat(tmp_prt_total.toFixed(2)))
            tmp_prt_total=0
            total_invoice()
            }
        else
            {
            document.form1.prt_qty.value=""
            document.form1.prt_price.value=""
            document.form1.prt_total.value=""
            document.form1.prt_qty.disabled=false
            tmp_prt_price=document.form1.s1.value;
            document.form1.prt_price.value=("$"+tmp_prt_price)
            }
        }
    }


}

function totalup_prt()
{
document.form1.prt_qty.disabled=true
tmp_prt_qty=document.form1.prt_qty.value
tmp_prt_total=(tmp_prt_price*tmp_prt_qty)
document.form1.prt_total.value=("$"+tmp_prt_total. toFixed(2))
document.form1.prt_total.value=document.form1.prt_ total.value
total_invoice()
}

 
Old January 11th, 2007, 05:14 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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





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 09:05 AM
mysql discount table hosefo81 PHP Databases 0 December 12th, 2003 10:58 PM
Discount dannomite Wrox Book Feedback 3 June 5th, 2003 10:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.