hide the submit button after a form is submitted (without AJAX)

with JavaScript by hiding the button on form submit.

23

Arun Kr.
17-Jul-25

Hide Submit Button on Form Submit (No AJAX)

<form method="post" onsubmit="hideSubmitBtn(this)">
    <!-- Your form inputs here -->

    <button type="submit" id="submitBtn">Submit</button>
</form>

<script>
function hideSubmitBtn(form) {
    // Optional: disable all submit buttons inside this form
    const btn = form.querySelector('button[type="submit"]');
    if (btn) {
        btn.disabled = true;
        btn.innerText = 'Submitting...'; // Optional feedback
    }
}
</script>

 

What This Does:

  • When the user clicks Submit, onsubmit="hideSubmitBtn(this)" is triggered.

  • The button is immediately disabled and hidden.

  • Then the browser proceeds with the normal form submission to PHP (no AJAX required).

 

@Since 2024 Arun'Log Powered by Arun Git