February 1, 2002 - Preventing Double Payments | WebReference

February 1, 2002 - Preventing Double Payments

Yehuda Shiran February 1, 2002
Preventing Double Payments
Tips: February 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

One of the problems in e-commerce is how to protect the user from making mistakes. It's even more critical when your protection target is on-line payments. Usually, you need to send a request to a credit authorization system, get back a transaction number, and only then charge the user's bank account. A common scenario is that the credit authorization number is late to come back, the user becomes anxious, and he or she presses the Charge My Account button again.

One way to protect the user is by disabling the tempting button after the user clicks it. Here is the button first:

Try it. See how the button gets disabled after you click it. Refresh the page to enable it again. The assumption here is that the authorization number will arrive by the time the user refreshes his or her window. Here is how the above button is defined:

  <BUTTON ID="tuition" 
    onclick="javascript:document.getElementById('tuition').disabled=true">Charge
    My Account!</BUTTON>
Notice the JavaScript statement that disables the button:

  document.getElementById('tuition').disabled = true
This tip works for IE and N6.