Solved

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

Posted on 2013-01-23
16
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 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