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();" >
</form>

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

NOTE
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”.

Tags: disable button onclick, onclick disable button, uncaught typeerror: property \submit\ of object #<htmlformelement> is not a function, disable button when clicked, https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1831 bXljDxFNBs-KE-BVOIn5QT2SI6sUngKYjXMS4j4s6qEeepRE1ZKm3JoHQecZbqlY 4b4a2e823ebe2882630f9310ba5e2dc2ddb86643&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme, https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1835 OOZwk0uGpHL8VTxBojMx1bQmkkdROYjQNRShC-vdRcp2zqTSA60AKKELb3mKHexT 2733867c9c8f9673ab9be3a2dfbe2308d0118468&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme

Uncaught SyntaxError: Unexpected end of input error in Chrome

Today, while I was working with jQuery I ran on this error “Uncaught SyntaxError: Unexpected end of input” while troubleshooting my code in Chrome. And since Chrome it didn’t report error on any specific line I had to Google for it 🙂

And after opening few pages I found out that this error codes happens when you forget closing “}”. That can happen often when writing JavaScript and especially jQuery code. Locating that is not easy, especially if you’r code is sloppy and you have a lot of it. Luckily my code is always very nicely written so I got it solved quickly. But in case you’r code is really messy or is compressed (with some JavaScript compressing tool like jscompress.com) you can copy/paste your javascript code into jsbeautifier.org, click on “Beautify JavaScript” (select the options you want on the right side of the screen first) and see if all of the indentations are correct. Beautiful and Geeky.

Tags: Uncaught SyntaxError: Unexpected end of input, uncaught syntaxerror unexpected end of input line 1, unexpected end of input, uncaught, uncaught syntaxerror unexpected end of input, unexpected end of input line 1, javascript unexpected end of input line 1, javascript unexpected end of input, jquery unexpected end of input, uncaught syntaxerror: unexpected end of input line 1, syntaxerror: unexpected end of input, syntaxerror unexpected end of input, unexpected end of input js, decompression problem unexpected end of input file or i/o error, UncaughtSyntaxError:UnexpectedendofinputerrorinChrome|GeekTipsnTricks, uncaught syntaxerror unexpected end of input jquery, decompression problem unexpected end of input file or i o error, unexpected end of input javascript line 1, https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1829 0Jf9nXvzqCcl4_yrqr_gjMrPl_q4rvMtFjG3GbULcy671TgGh9-Ckz6hRF1R2EIx d22aed3bb719ca11ac849cb0c5c9c8a8d9e33bbc&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme, swimrzi, RENY, 6MAB