Link to home
Start Free TrialLog in
Avatar of jameskane
jameskane

asked on

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

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)
Avatar of Chris B
Chris B
Flag of Australia image

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
Avatar of jameskane
jameskane

ASKER

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
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
Avatar of Tomarse111
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
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
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>
SOLUTION
Avatar of Tomarse111
Tomarse111
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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;"/>
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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The addition of the forced submit, should do the job as well :)
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.
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.
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