Disable button onclick to prevent double submition

Today I had an simple task: to disable a button after a click to prevent double submitting the form data. I wanted to solve it as simple as possible. So here’s the final solution

<form method="POST" action="">
<input type="submit" value="Submit" name="submitBtn" onclick="this.disabled=true;this.form.submit();" >

It works like a charm – it disables the submit button and it submits the data.

I have found a interesting bug in Chrome. My input button had its name set to “submit” (name=”submit”), but then chrome was reporting following error:

Uncaught TypeError: Property 'submit' of object #<HTMLFormElement> is not a function generate-form.php:onclick

The reason for the error when trying to call form.submit() is that your submit button is called “submit”. This means that the “submit” property of your Form object is now a reference to the submit button, overriding the “submit” method of the form’s prototype. Renaming the submit button allowed me to call the submit() method without that error, so I renamed it to “submitBtn”.

This post helped you out? Why not buy me a coffee?

Your message for me
Tags: disable button onclick, onclick disable button, uncaught typeerror: property \submit\ of object #<htmlformelement> is not a function, javascript disable onclick after click, onclick disable, html disable button click event, onclick disable html input, onclick javascript disable, javascript div disable click events, salesforce onclick button disabling, javascript button disable click, html if button clicked disable it, html disable onclick, how to temporarily disable mouse click HTML, asp net actionlink disable on cllick, blur submit button onclick html, chrome onclick disabled, disable button javascript onclick, disable href onCLick, disable onclicktop, disabling button after click in chrome html, disabling button from click events in HTML, how to call click event when button disabled, how to disable hyperlink onclick event, a link onclick disable
How to backup data on second HDD using Google Drive
How to edit .po language files in WordPress themes


  1. Thanks, nice and straight forward

Leave a Reply

Your email address will not be published / Required fields are marked *