Results 1 to 8 of 8

Thread: Looking for a form script that performs simple arithmetic functions

  1. #1
    Join Date
    Dec 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Looking for a form script that performs simple arithmetic functions

    I am looking for a simple script for an ordering form that multiplies price by number of items and then sums up the total prices. thanks..

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    This can be done a number of ways. Can you please be more specific to what your needs are, possible post some code or a link to an example of what you have?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Dec 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Product Unit Price Qty Total Price
    Product 1 $3.29 4 $13.16
    Product 2 $4.10 7 $28.70
    Product 3 $1.98 1 $1.98
    Product 4 $5.75 3 $17.25
    Product 5 $3.89 10 $38.90
    Total Order $99.99

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Okay that doesn't really tell me anything but I'll just assume some things. This may no function exactly but is an example.

    Code:
    <script type="type/javascript">
    var product1_q = document.getElementById("product1_quantity").value;
    //assuming this is an input with type text for quantity wanted this could also error if they enter text should check that as well
    var product1_p = document.getElementById("product1_price").value;
    //assuming this is input type hidden with the price as 12.30 no $ or other characters
    
    
    product1_total = product1_p * product1_q;
    var current_total = product1_total;
    
    var product2_q = document.getElementById("product2_quantity").value;
    //assuming this is an input with type text for quantity wanted this could also error if they enter text should check that as well
    var product2_p = document.getElementById("product2_price").value;
    //assuming this is input type hidden with the price as 12.30 no $ or other characters
    
    product2_total = product2_p * product2_q;
    current_total = current_total + product2_total;
    products_total = product2_q + product1_q;
    </script>
    I've done this in javascript because that is the forum you posted this in. You probably want to process a request like this in php or some other server language though.
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Dec 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Does Javascript work in an email?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Nope.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Dec 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Can HTML be used to perform the same calculations? or is there some other language available that can perform these calculations in an email?

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    No. You can perform them before you send the email, preferably on the server side as part of the email process.

    That's what happens when you order something online and get a receipt email. The server calculates things up, if it hasn't already, and composes an email to the address you supplied.

    An alternative would be to create a page just for the person and send them the address in an email. But once again, the server should be involved with this if it has any chance of being secure.

    If what you're proposing is some sort of e-commerce, you really need an ssl (https server) or a third party service like PayPal to do things securely.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •