SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,647
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Adding tax via a checkbox?

    I have a form, in it I have a combo box to determine the tax rate.
    HTML Code:
     <select name="tax" size="1">
            <option value=".0775">7.75%</option>
            <option value=".08">8%</option>
    ...
        </select>
    I created a checkbox next to any items price to determine if that product is taxed. How can I update the Total to include tax (if its selected)?
    Thanks...
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    You could have a non-editable tax field for each item that's created by javascript.

    The script can then update the tax field, which you will include in the total.

    If javascript is not enabled, the tax field won't appear, but the php script will have the information from the checkboxes about how much tax to apply to what items.

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,647
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    woaw, thats nice...
    How would I set that up?
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    When the page loads it would run a function to create the tax fields.

    Code HTML4Strict:
    <body onload="initTax()">

    The initTax() function would create html like this, just after each item price

    Code HTML4Strict:
    <input type="text" name="itemtax" class="tax" readonly="true" />

    The then select element and each checkbox would have an onchange function

    Code HTML4Strict:
    <select id="taxrate" name="taxrate" size="1" onchange="updateTaxAndTotal()">
    <input type="checkbox" name="taxable" checked="" onchange="updateTaxAndTotal()" />

    The updateTaxAndTotal() function would call two functions.
    • updateTax() takes the new tax rate and applies it to the appropriate tax fields
    • updateTotal() updates the total price on the page


    The important thing is to get the actual process working first without javascript, then use scripting to add the functionality that we want.
    This way things like how the tax is processed won't change, whether you have javascript going or not.


Bookmarks

Posting Permissions

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