Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling submit button cancels form submit

I have a form like this:

<form action="lol.php" method="POST">
<input type="text" name="fe" />
<input type="submit" id="submitbtn" value="submit" onclick="this.disabled = true;" />
</form>

and in Firefox it works perfectly, but in Internet Explorer (latest version) the button becomes disabled but the form does not submit. I have also tried:

<form action="lol.php" method="POST" onsubmit="document.getElementById('submitbtn').disabled = true">

and removed the onclick code from the submit button, but that had the same effect. What code should I use so that it works on all browsers?

like image 710
fitz Avatar asked Oct 24 '25 02:10

fitz


1 Answers

Ok, so the good hack is to prepare second fake button that does nothing:

<form action="lol.php" method="POST">
<input type="text" name="fe" />
<input type="button" id="submitbtnDisabled" disabled="disabled" value="submit" style="display:none;" />
<input type="submit" id="submitbtn" value="submit" onclick="this.style.display='none'; document.getElementById('submitbtnDisabled').style.display='inline';" />
</form>

Note:

Because you said you're not using jQuery I'm using standard JavaScript. The only suggestion is to use unbotrusive JavaScript and move inline CSS to a stylesheet just to separate scripts and styles from HTML.

like image 118
rochal Avatar answered Oct 26 '25 15:10

rochal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!