Disable submit button cancels submit form

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 it works fine in Firefox, but in Internet Explorer (latest version) the button becomes disabled, but the form is not submitted. I also tried:

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

and removed the onclick code from the submit button, but the same effect. What code should be used to work on all browsers?

+3
source share
5 answers

Ok, so a good hack is to prepare a 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:

, jQuery, JavaScript. - unbotrusive JavaScript CSS , HTML.

+5

. , , . .

+1

:

onclick="this.disabled=true;return true;"

MS exploder . ( , , FireFox)

+1

.

Try:

<input type="submit" id="submitbtn" value="submit" onclick="setTimeout(function () { this.disabled = true;}, 0)" />
0

, jquery.

:

$('#submtbtn').submit(function() {
   $(this).attr('disabled', 'disabled');
});

, .

-1

Source: https://habr.com/ru/post/1757762/


All Articles