Skip to content

Checkout button clicked twice

A checkout page posts the order when “Place order” is clicked, then shows a confirmation and hides the button. The button stays clickable while the request is pending. A second click in that time sends a second POST, and the page shows two orders. Clicking once and waiting, the way a manual test does, never shows it.

checkout.js
// Places the order and shows each confirmation the server sends back.
const button = document.getElementById('place-order');
const status = document.getElementById('status');
const orders = document.getElementById('orders');
const continueLink = document.getElementById('continue');
button.addEventListener('click', async () => {
status.textContent = 'Placing your order...';
const response = await fetch('/orders', { method: 'POST' });
const { id } = await response.json();
const item = document.createElement('li');
item.className = 'order';
item.textContent = `Order ${id} confirmed`;
orders.append(item);
status.textContent = 'Thank you!';
button.hidden = true;
continueLink.hidden = false;
});

See how Bombadil finds and fixes it.

Last updated: