Solved

How to "idiot proof" submit buttons against a DOUBLE CLICK

Posted on 2013-01-23
16
271 Views
Last Modified: 2013-02-01
I have an application which is working perfectly, except in one section where a DOUBLE sale in recorded in the database if the SUBMIT button is double clicked, instead of single click. Apart from putting a warning note beside the button, is there a more elegant fix ?

Thanks very much in advance

Notes on environment

Windows 7
Dreamweaver dev env
Coldfusion
MS Access for data repository use only (no programming)
0
Comment
Question by:jameskane
  • 6
  • 5
  • 2
  • +1
16 Comments
 
LVL 28

Expert Comment

by:burrcm
ID: 38809473
Don't know the system, but perhaps a check for duplicates as part of the onclick code? I could do this in Access easily....

Chris B
0
 

Author Comment

by:jameskane
ID: 38809581
Had a look Chris, but don't think the problem is there. The submit button simply sends data via a form to the database -  can(t see any duplication errors
0
 
LVL 28

Expert Comment

by:burrcm
ID: 38809622
OK. You did imply I think that two clicks = two entries, so a check for same seemed reasonable. Out of my depth here. Can you prevent / mask a double click by setting some timer event on a click? Just throwing out ideas.....

Chris B
0
 
LVL 15

Expert Comment

by:Tomarse111
ID: 38809656
You could disable the submit button onClick ?

or set a session value to check against its existence. If it exists then don't allow the second submit?

Let me know if that's up the right alley and I will help if I can

Tom
0
 

Author Comment

by:jameskane
ID: 38809662
I think what's needed is some sort of java code to be wrapped around the button which causes all clicks to be subpressed apart from the first one. Easier said than done I'm sure !!
Thanks Chris for taking time to look at this

jim
0
 

Author Comment

by:jameskane
ID: 38809714
This is the code around the submit button, which has the name "PAYER MAINTENANT"              

<td colspan="2" align="center"><input type="submit" name="pay" id="Pay" value="Payer Maintenant" />
      <input name="deltacumcost" type="hidden" id="deltacumcost" value="<cfoutput>#form.deltacumcost#</cfoutput>" />
      <input name="YTDpurchases" type="hidden" id="YTDpurchases" value="<cfoutput>#form.cumcost#</cfoutput>" />
      <input name="cost_libre" type="hidden" id="cost_libre" value="<CFOUTPUT>#cost_libre#</CFOUTPUT>" />
      <input name="cost_enroll" type="hidden" id="cost_enroll" value="<CFOUTPUT>#cost_enroll#</CFOUTPUT>" />
      <input name="memberID" type="hidden" id="memberID" value="<cfoutput>#session.memberID#</cfoutput>" />
      <input name="adjustments" type="hidden" id="adjustments" value="0" />
      <input name="owed" type="hidden" id="owed" value="<cfoutput> #owed# </cfoutput>" />
      <input name="positivedeltacumcost" type="hidden" id="positivedeltacumcost" value="<cfoutput> #positivedeltacumcost# </cfoutput>" /></td>
  </tr>
</table>
</form>
0
 
LVL 15

Assisted Solution

by:Tomarse111
Tomarse111 earned 250 total points
ID: 38809760
OK, so is your submit button a simple HTML <input type="submit"> ? If so:

<form action="" method="post">
	<input type="submit" value="OK" onClick="this.disabled=true;">
</form>

Open in new window


Should work for you
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:jameskane
ID: 38810415
Many thanks for taking time. This worked for the first sale to the person -  I double clicked the button and did not get a doubling of the sale. However, on running another transaction, it
seems like the botton is not working. It appears to work - but the actual sale does not get reported. Looks like I disabled the submit button with the first double click and it did not come back on again  - my code is below.

<tr align="left">
    <td colspan="2" align="center"><input type="submit" name="pay" id="Pay" value="Payer Maintenant" onClick="this.disabled=true;"/>
0
 
LVL 15

Expert Comment

by:Tomarse111
ID: 38810534
Does your submit button post a form? as in does the page refresh upon itself? This could be a caching thing.

But you could force it to be not disabled on its return by adding the following into the body tag:

<body onLoad="document.getElementById('Pay').disabled=false;">

Open in new window

0
 

Accepted Solution

by:
jameskane earned 0 total points
ID: 38810663
Hi  Tomarse111,

seems to be working with the following - what you gave me, plus the addition of  this.form.submit();  

onClick="this.disabled=true;this.form.submit();"

Need to do some more testing on it -  

Wondering if I need the body tag additioon ??
0
 
LVL 15

Expert Comment

by:Tomarse111
ID: 38810706
The addition of the forced submit, should do the job as well :)
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 38810744
Personally, I think the client side approach is a bad idea. (In general, don't trust anything from the client side,...ever)

What I do at the end of my checkout process is expire a session variable cartid

pseudo code

<cfif cartid neq "">
<cfquery>    
insert order into db
</cfquery>
    <cfset session.cartid = "">
<cfelse>
<div> Order already submitted</div>
<cfabort>
</cfif>

I actually send some ajax back rather than use the abort but that's the basic idea.
0
 

Author Comment

by:jameskane
ID: 38824172
I've requested that this question be closed as follows:

Accepted answer: 250 points for Tomarse111's comment #a38809760
Assisted answer: 0 points for jameskane's comment #a38810663

for the following reason:

Thanks everyone for taking time to look at this. i got the solution mostly from you Tomarse111 -  it put me in the right direction, but was't turn key.<br /><br />Also, thanks for the input SidFishes - got to keep that point in mind for the future.
0
 
LVL 15

Expert Comment

by:Tomarse111
ID: 38824173
Hi

As stated by the question asker in both his comments and reason for closing, my solution is what he used in the end, therefore i would assume either i get full points or at the very least an assist (by definition; i assisted him in completing his objective).

As ever i will bow to the moderators decision

Many thanks

Tom
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now