Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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()
    }

  • #2
    New Coder TripperTreats's Avatar
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    ."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •