-1

I have so many HTML pages in my application and we have issues with impatient user submitting the same input multiple times, I want to use JavaScript or JQuery to disable all type=Submit fields or at least disable the submitted field. I am trying to avoid HTML changes and handle this with just script.

Rookie
  • 33
  • 4

2 Answers2

0

You can add a disabled attribute when the form is submitted, or when the button is clicked...

$('form').on('submit', function () {
    $('button', this).attr('disabled', 'disabled');
});

You will need to extend this example to handle validation failures or AJAX requests (i.e. to re-enable the button).

Or if you have input's with a type of submit...

$('form').on('submit', function () {
    $('input[type=submit]', this).attr('disabled', 'disabled');
});
Fenton
  • 241,084
  • 71
  • 387
  • 401
0

I've recently started adding a loading icon that pops up to show the user that something is being processing. This loading icon would sit inside of a container that takes up the entire page (absolute position) and has an opacity of 0.5 for example. This will gray out everything in the background as well as prevent the user from being able to click any other buttons.

Here's the HTML

<div class="loader-container" >
   <div class="loader"></div>
</div>

And the CSS

.loader {
            border: 10px solid #f3f3f3; 
            border-top: 10px solid #3498db;
            border-radius: 50%;
            width: 75px;
            height: 75px;
            animation: spin 2s linear infinite;
        }
        .loader-container{
            background: rgba(0,0,0,0.35);
            position: fixed;
            z-index: 5;
            top: 0; left: 0; right: 0; bottom: 0;
            display: flex;
            align-items: center;
            justify-content: center;
        }

You'll obviously have to toggle the loader-container's visibility when the user clicks submit.

James Q Quick
  • 429
  • 3
  • 5