How to prevent forms from being submitted twice

To prevent forms from being submitted twice, such as when a user double-clicks on the Submit button, add the following JavaScript code, including the opening and closing tags, on the Web References tab in the Form configuration panel. This is supported in Internet Explorer 9 and later, Edge, Chrome, and Firefox.

// if $selectedObject is undefined, we are not in the form designer
    if (typeof $selectedObject === "undefined")
    {
        var windowFirstLoad=true;
    
        // Standard page Load
        window.onload = function ()
        {
            preventDblSubmit();
        }
        // Ajax page load
        function pageLoad()
        {
            if (!windowFirstLoad)
            {
                preventDblSubmit();
            }
            else
            {
                windowFirstLoad=false;
            }
        }
   
        function preventDblSubmit()
        {    
            var sourceIsButton = false;
            var submitButton = document.getElementById('submitButton');
            var draftButton = document.getElementById('saveAsDraftButton');
    
            if(submitButton)
            {
                submitButton.addEventListener("click", function(){
                    sourceIsButton = true;
                });
            }
            
            if(draftButton)
            {
                draftButton.addEventListener("click", function(){
                    sourceIsButton = true;
                });
            }
          
            form1.addEventListener("submit", function()
            {                 
                if(!sourceIsButton)
                {
                    return true;
                }
                
                // If the page contains .NET validators, check the Page_IsValid variable
                if(typeof Page_IsValid !== 'undefined')
                {                    
                   if (!Page_IsValid)
                   {
                       return false;   
                   }
                }
                                
                // Prevent further clicks
                if(submitButton)
                {
                    submitButton.onclick=function(){ return false; };
                    submitButton.ondblclick=function(){ return false; };    
                }
                
                if(draftButton)
                {
                    draftButton.onclick=function(){ return false; };
                    draftButton.ondblclick=function(){ return false; };    
                }
                return true;    
            });
        }
    }