Solved

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

Posted on 2013-01-23
16
279 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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