Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Setting Disabled Attribute doesn't submit forms on Safari iOS

I am trying to do a fancy button with some animations to disable it once clicked (or touched on mobile phones). However; I am facing an issue. The issue is that setting the disabled attribute does complete the animation, but doesn't submit the form. It's working on PCs, though!

<form class="needs-validation" action="" method="post" enctype="application/x-www-form-urlencoded" role="form">
    <div class="card shadow">
        <div class="card-body">
            <h2 class="card-title text-center">Form</h2>
            <div class="form-floating mb-3">
                <input class="form-control" name="id" placeholder="Enter ID" type="text" required>
                <label>ID<label>
            </div>
            <div class="mb-3 text-end">
                <button type="submit" class="btn btn-primary" name="submit" id="submit"
                    onclick="submitForm();">Search</button>
            </div>
        </div>
    </div>
</form>
function submitForm() {
    var submitBtn = document.getElementById("submit");
    submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> &nbsp; Searching...';
    submitBtn.setAttribute("disabled", true);
}

What am I missing or is it a bug with Safari on iOS?

EDIT:

Tried ontouchend=submitForm(); but didn't solve the issue.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Edit: simpler answer

Just move your listener/handler from the button's onclick to the form's onsubmit.

  1. This causes your listener/handler to only be invoked after the submit process is invoked, so setting disabled doesn't affect that process.
  2. This also means you don't need to call form.submit() manually
  3. You can then have the original name="submit" on the element (although I wouldn't advise it as it overwrites the submit function).

Original answer

This happens because the onclick event handler occurs before the form is submitted. Subsequently, when it is time to submit the form, the submit input is disabled and so the form should not submit.

Also you have named your button "submit" with name="submit". Change the name to something else, like "submitButton" to avoid affecting the native submit function.

Now you can call submit in your submitForm handler:

function submitForm() {
    var submitBtn = document.getElementById("submit");
    submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> &nbsp; Searching...';
    submitBtn.setAttribute("disabled", true);

    // calling submit manually
    form.submit();
}

Details:

Named inputs of a form are assigned to the object representing the form.

For example, if you have an form named myForm and it has an input named firstName, then firstName can be accessed in JavaScript as such: myForm.firstName.

Now you have an input called "submit" (the submit button). Guess what's also called submit on the form object? The method that is actually used to actually "submit" your form.

When you have an input called "submit" the method to submit gets overwritten to something completely different and it's no longer pointing to the submit function, hence submit doesn't work no longer.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!