...

View Full Version : applying discount



blkskull
01-11-2007, 09:58 PM
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()
}

TripperTreats
01-12-2007, 12:52 AM
There are many ways to do this, as with most javascript projects. Here's what I would do (I will sketch out the process):


var taxRate = .086 (or whatever the tax rate is);
var products = new Array();
// products will be a set of arrays; each array will contain the product and its price with tax
products[0] = ["Epson Stylus C88",99.01*(1+taxRate)];
// if Epson is to be taxed, for instance)
products[1] = ["Canon Pixma IP1600",38.05];
// if Canon will not be taxed, for instance
etc...
Then, create your drop down list of products with javascript:


document.write('<select name="s1" onChange="which_prt()">');
document.write('<option value="none" selected></option>');
for (var i=0; i<products.length; i++) {
document.write("<option value="\"+products[i][1]+"\">"+products[i][0]+" </option>");
}
document.write('</select>');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum