Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-11-2007, 08:58 PM   PM User | #1
blkskull
New Coder

 
Join Date: Nov 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
blkskull is an unknown quantity at this point
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()
}
blkskull is offline   Reply With Quote
Old 01-11-2007, 11:52 PM   PM User | #2
TripperTreats
New Coder

 
TripperTreats's Avatar
 
Join Date: Oct 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
TripperTreats is an unknown quantity at this point
There are many ways to do this, as with most javascript projects. Here's what I would do (I will sketch out the process):

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

Code:
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>');
__________________
Psychedelic digital art at www.trippertreats.com.

"And in the end, the love you take
is equal to the love you make
."
TripperTreats is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:41 PM.


Advertisement
Log in to turn off these ads.