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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automatically Calculate based on input

    I have a form for credit card processing. Currently the form field that collects the amount based on the users input looks like...

    Code:
    <input type="text" name="chargetotal" value="">
    When the form is submitted, it calls to a php script that includes $_POST["chargetotal"] and that amount it charged to the credit card.

    I would like to add a text area that automatically calculates and adds 3% to the amount the user enters. This way they know the exact amount they will be charged.

    I assume I can just multiply $_POST["chargetotal"] by *.03 before the script sends the amount to charge to the bank so this field does not actually have to be the one the next page uses. It could just be a visual.

    How do I make a new text area that automatically updates while leaving "chargetotal" in tact so on submit, the php script picks up $_POST["chargetotal"] properly?

    Thanks,
    Rich

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Code:
    <input type="text" name="chargetotal" value="" 
        onchange="this.form.grandtotal.value = ( 1.03 * ( isNaN(this.value) ? 0 : this.value ) ).toFixed(2);"
        />
    ...
    Grand total (with credit card fee): <input name="grandtotal" readonly />
    Now... If your "chargetotal" field is ITSELF the result of some JavaScript calculations, then the onchange won't work. You'll have to show us more code, in that case.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    As an aside, I will never do business with any firm that makes a charge for using a credit card. Nor will I pay a "booking fee". Or an "administration fee".

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Old Pedant, Thank you so much. Worked perfectly.

    Philip M, do you buy gasoline? In my state (New York), there are 2 prices listed at the pump. Cash price and Credit price. Do you use a credit card or always pay cash? The fee is one thing and a cost of doing business, but a rewards card tacks on an additional 2%-3% to the merchant. I believe it is unfair for me, as a business man to have to pay for miles or whatever the reward may be.

    Just my opinion but thank you so much for the coding help

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by RichGags View Post
    Old Pedant, Thank you so much. Worked perfectly.

    Philip M, do you buy gasoline? In my state (New York), there are 2 prices listed at the pump. Cash price and Credit price. Do you use a credit card or always pay cash? The fee is one thing and a cost of doing business, but a rewards card tacks on an additional 2%-3% to the merchant. I believe it is unfair for me, as a business man to have to pay for miles or whatever the reward may be.

    Just my opinion but thank you so much for the coding help
    I am not an American, but if any petrol station in the UK tried to charge a premium for using a credit card they would soon be out of business.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    It is a common practice here in the US for credit cards to "kick back" a percentage of all or some specific charges to the credit card holder. 1% is most typical, but some cards kick back more for some charges, quite often including petrol (gasoline) purchases.

    So you do have to wonder at the logic of it all: The credit card processing company charges the gas (petrol) station 3% of the amount and then kicks back 1% to 2% to the credit card user as an incentive to use the card.

    It's no wonder than some stations have switched to "cash price" and "credit price". Not their fault; the credit card companies have pushed them into it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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