jQuery disable button on page by classname

jQuery disable button on page by classname

October 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
jQuery disable button on page by classname

Handling Button Disabling and Form Submission in Magento One Page Checkout

Double submission of orders is a common issue faced by e-commerce websites using one-page checkout systems like Magento. This often occurs when customers press the submit button multiple times accidentally, leading to duplicate orders and charges. To prevent this, it’s crucial to disable the button after the first click until the order processing is complete.

Let’s start by understanding the different approaches to handle this situation:

1. Disabling the Button on Click using jQuery

The simplest way to achieve this is by disabling the button directly in the onclick attribute of the HTML tag itself. However, this approach has some limitations and is not recommended for larger applications.

<button type="submit" title="Place Order" class="button btn-checkout"
        onclick="review.save(); this.disabled = true;"> Place Order </button>

While this works, it lacks flexibility and can’t be easily extended to handle more complex scenarios. Moreover, if you want to enable the button after some time or based on a certain condition, this method becomes impractical.

2. Removing Onclick Attribute and Using jQuery Click Event Handler

A better approach is to remove the onclick attribute altogether and use a jQuery click event handler instead. This provides more control over the event and allows you to add additional logic if needed.

Firstly, remove the onclick attribute from your button:

<button type="submit" title="Place Order" class="button btn-checkout"> Place Order </button>

Then, in your JavaScript or jQuery code, attach a click handler that disables the button and triggers the order submission process.

$('.button.btn-checkout').click(function() {
  $(this).prop('disabled', true);
  review.save();
});

This method is more flexible. You can add additional checks before disabling the button or enabling it later using the prop() function.

3. Disabling Form Submission

To prevent double submissions, you should also disable the form submission itself. This ensures that even if a customer presses Enter in the keyboard shortcut for submitting forms, the order won’t be duplicated.

You can achieve this by adding onsubmit="return false;" to your form tag:

<form id="checkout-form" action="#/" method="post"
      onsubmit="return false;">
  <!-- Form fields here -->
</form>

In combination with the button disabling approach, this provides a robust solution for preventing duplicate submissions.

4. Best Practices

For larger applications or more complex requirements, consider using AJAX to submit the form asynchronously:

  • Disable the button and display a loading indicator when the order submission process begins.
  • If the submission is successful, redirect the user to the order confirmation page.
  • If there are errors during the process, re-enable the button and show an appropriate error message.

This approach provides a better user experience and allows you to handle different scenarios more efficiently.

Conclusion

Preventing duplicate orders in Magento one-page checkout requires a combination of disabling the submit button and handling form submission. The best practice is to use jQuery click event handlers for disabling buttons and controlling form submissions using AJAX for asynchronous processing.

By following these recommendations, you can ensure a smooth checkout experience for your customers while preventing unwanted double submissions that can lead to financial losses and customer dissatisfaction.

To learn more about optimizing Magento performance and implementing advanced features like asynchronous form submissions, consider exploring our comprehensive guide to Magento development at https://laravelcompany.com/magento-development-guide.

Remember, the key lies in combining proper front-end handling with backend validation and order management processes to create a robust and secure checkout system.

Happy coding!

Checkout Database Orders Customers

Our network