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 09-20-2012, 03:42 AM   PM User | #1
RichGags
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
RichGags is an unknown quantity at this point
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
RichGags is offline   Reply With Quote
Old 09-20-2012, 06:13 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-20-2012, 07:52 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 09-20-2012, 01:42 PM   PM User | #4
RichGags
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
RichGags is an unknown quantity at this point
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
RichGags is offline   Reply With Quote
Old 09-20-2012, 03:50 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 09-20-2012, 10:27 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant 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 05:18 AM.


Advertisement
Log in to turn off these ads.