What I am trying to achieve is something like this:
User clicks a button -> button becomes disabled (and a spinner appears on top) -> form is submitted.
I tried this and it works only sometimes (inside the HTML button):
onclick="
this.classList.toggle('button--loading'); // triggers spinner (created in CSS)
this.disabled=true; // disabled button
this.form.submit();" // submits form
Sometimes it works, sometimes it skips triggering the spinner and simply disables the button and submits afterwards. I am thinking that implementing a delay after the spinner is created will make it work 100% of the time, but I cannot figure it out.
Please note that I am quite a beginner with coding and really trying to find out how things work. Thanks!