Search code examples
coldfusiontimeoutcoldfusion-9coldfusion-10cfml

Coldfusion - How to prevent multiple clicks?


I have a button (anchor tag) that send a confirm message if you press it. The problem is that for example if you press it 5 times very quickly it will send 5 confirm messages, if you press it 2 times it will send 2 messages.

This can occur when the user has low connection speed and while the page is refreshing he presses again the button.

How can I manage this situation? I though of disabling the button but for other reasons this is not possible.

<a class="msg" href="/manage/conversations.cfm?destination=#destination#">
        #ucase(request.l('Send'))#
</a>

Thank you for your time


Solution

  • Ultimately, you need to have code on your server to prevent processing the link multiple times from the same user.

    However, to solve the UI issue, have you link call a function instead of the cf file directly.

    <a class="msg" href="javascript: processLink(#destination#);">
            #ucase(request.l('Send'))#
    </a>
    
    <script>
    runCount = 0;
    
    function processLink(destination){
    runCount++;
    
    if (runCount == 1){
     window.location.href = "/manage/conversations.cfm?destination=" + destination;
    }
    
    }
    </script>