Hi Sirs,
I need to see others buttons staying disabled when the specific button is clicked.
When you click on the button the rest of buttons just stay one second disabled (Late come back able).
I known that is because of the submit's type button. But I need to keep these buttons as submit's type. How can I resolv it please. Thanks.
If I am not clear. Please inform me.
Raghunath BhukanPosted Jan 4, 2026, 8:50 AM
This code will work for both the types of buttons - "submit" & "button"
/* Base button */
.btn { display: inline-flex; align-items: center;justify-content: center; padding: 10px 18px;font-size: 14px;font-weight: 500; border-radius: 4px; border: 1px solid transparent;cursor: pointer; transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease; min-width:80px;}
/* Primary button */
.btn-primary {
background-color: #396ebb;
border-color: #063a86;
color: #fff;
}
.btn-primary:hover {
background-color: #e6a307;
border-color: #ae7d09;
}
/* Disabled look (Bootstrap-like) */
.btn-disabled,.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
/* Spinner inside button */
.btn-spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; margin-right: 6px; }
@keyframes spin {
to {
transform: rotate(360deg);
}
}
/*loader*/
.loader { width: 24px; height: 24px; border: 4px solid #ccc; border-top: 4px solid #007bff; border-radius: 50%; animation: spin 1s linear infinite; margin-top: 10px; }
.hidden {
display: none;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
document.addEventListener("DOMContentLoaded", () => {
const form = document.querySelector("form");
const buttons = document.querySelectorAll(".action-btn");
const loader = document.getElementById("loader");
let isSubmitting = false;
buttons.forEach(clickedButton => {
clickedButton.addEventListener("click", (e) => {
e.preventDefault(); // stop immediate submit
if (isSubmitting) return;
isSubmitting = true;
// Disable all other buttons
buttons.forEach(button => {
if (button !== clickedButton) {
button.disabled = true;
// Optional
button.classList.add("btn-disabled");
}
});
// Show spinner
loader.classList.remove("hidden");
// Optional: change button text
clickedButton.textContent = "Submitting..."
// Optional: disable clicked button too , if u want you can comment this.
clickedButton.disabled = true;
// Wait 3 seconds, then submit form or set the setTimeout relevant to you
setTimeout(() => {
form.submit();
}, 2000);
});
});
});
IsraelPosted Jan 8, 2026, 10:56 AM
@Raghunath B
Sorry Raghunath B, I saw it right now. Thank you a lot. Your code is clean and very simple to understand it. Be blessed ! :-)
Raghunath BhukanPosted Jan 8, 2026, 5:31 AM
Hi Israel,
Make sure to read and understand all the comments in the code snippet.
Disabling clicked button is optional. You can enable it by commenting the code line given below or set it disabled = false.
// Optional: disable clicked button too, if u want you can comment this.
clickedButton.disabled = true;
Thanks.
IsraelPosted Jan 7, 2026, 10:47 PM
@Raghunath B
Hi, I come back again just for a little correction about your friendly codes. Its works as I need but my question is why when I click its disable even the clicked button. All button should be clicked but not the clicked one.
For instance, btn1,btn2,btn3,btn4 when the btn1 is clicked all buttons (btn2,btn3,btn4 should be disabled not the btn1 and so on).
Aarti JangidPosted Jan 6, 2026, 6:17 AM
This usually happens because Angular is re-rendering the component or change detection is resetting the button state.
Common things to check:
Make sure the
disabledstate is bound to a component variable, not set manuallyhtml
Ensure
isDisabledis not being reset after an API call, route change, or async updateIf you’re using
OnPush, confirm the value is updated immutably or viaChangeDetectorRefAvoid re-initializing the value in
ngOnInit()orngOnChanges()If inside a form, check that Angular isn’t re-enabling it due to form state changes
In short: the code may “work”, but Angular is updating the view again and re-enabling the button. Bind the disabled state properly and track where the value is getting reset.
KentmithPosted Jan 5, 2026, 3:47 PM
The main issue here isn’t the JavaScript — it’s the form submission lifecycle. When a submit button is clicked, the browser posts the form immediately, so the DOM resets before the disabled state can persist.
A simple fix is to explicitly stop the form from submitting until after you disable the buttons. For example:
If you’re doing any async work (AJAX, validation, etc.), you can also call
event.preventDefault()and submit manually once everything is ready.This pattern is commonly used to prevent double submissions and accidental re-clicks. We use a similar approach when building interactive sign configuration flows — if you’re interested in UX-focused frontend practices, you can see some related insights here:zerosigns.co.uk
KentmithPosted Jan 5, 2026, 3:42 PM
What you’re seeing is normal behavior for
type="submit"buttons — the form submits and the page refreshes, so any disabled state only lasts briefly. A cleaner way to handle this is to disable all buttons and prevent the default submit until your logic finishes.Instead of using inline
onclick, you can attach a single event listener and disable all buttons at once, then allow the submit to continue:This way, once any button is clicked, all submit buttons stay disabled until the request completes. It’s also easier to maintain than having multiple functions.
I’ve run into similar UI-state issues when working on interactive product tools for interior surface solutions — if you’re into architectural interior film or clean UI patterns, Samsung Interior Film has some interesting implementations worth checking out:surfexfilm.uk
IsraelPosted Jan 5, 2026, 12:46 PM
@Raghunath B
I do test quickly its sound great. If any problem I will come bback. Anyway it's works!!! Thank you.
IsraelPosted Jan 3, 2026, 10:17 PM
Dear Raghunath B,
The code you send doesnt work. That mean it's works very well ONLY with button as button's type (not as submit's type ). What's happen? Did you understand well my question :-)
In one word, the buttons come back to be able just once. Not after some second as you said here:
Raghunath BhukanPosted Jan 3, 2026, 4:34 AM
You’re right about the root cause:
because the buttons are type="submit", the form submits immediately and the page reloads, so the disabled state only appears for a moment.
You can keep the buttons as submit buttons and still solve this cleanly with one reusable, dynamic function.
Key idea (clean & reusable)
Use one single function for all buttons
Disable all other submit buttons when one is clicked
Let the form submit normally
(Optional) Re-enable buttons after 1 second if you stay on the page
Updated HTML (no duplicate functions)
Single reusable JavaScript function
Why this works
? Reusable – no hard-coded IDs
? Scales automatically (add more buttons, no JS changes)
? Keeps
type="submit"? Prevents double-clicks
If
company.phpreloads the page, the disabled state will disappear anyway (that’s normal).This solution is mainly to:
prevent multiple submits
avoid double clicks
improve UX before submit