disabled = "disabled" .class="form_is_loading" , and with any sabmite check for the presence of this class. But why do these checks, when you can do without them, just by making the button inactive?<input type = "submit" onclick = "this.disabled = true;">This simple option proposed in the aforementioned topics turns out to be insufficient and inoperable.
//// html file //////////////////////////////////////////// //////////////////////////
<form id = "the_form">
<input type = "submit" name = "send" value = "Publish">
<input type = "submit" name = "cancel" value = "Cancel">
</ form>
<script>
formUploader.prepareForm (document.getElementById ('the_form'));
</ script>
//// js file ////////////////////////////////////////////// ////////////////////////////
<script>
formUploader = {
prepareForm: function (form) {
// Each significant button of the form when you click should create a hidden field of the same name,
// so that information about which button was clicked is transmitted to the server
var allFormFields = form.getElementsByTagName ('input');
for (var i = 0; i <allFormFields.length; i ++) {
if (allFormFields [i] .type == 'submit' && allFormFields [i] .name) {
allFormFields [i] .onclick = function () {
formUploader.createHiddenField (this);
}
}
}
// Visualize the form as sent to the server on the onsubmit event
// (including making all buttons inactive)
form.onsubmit = function () {
formUploader.setFormLoading (form);
}
// Clear the visualization of the form (including making all the buttons active again)
// when leaving the page - on the global onunload event
window.onunload = function () {
formUploader.clearFormLoading (form)
}
},
setFormLoading: function (form) {
// Create visualization of form loading and make all buttons inactive
// disabled = true;
},
clearFormLoading: function (form) {
// Clear the form from loading visualization and return the buttons to the active state
// disabled = false;
},
createHiddenField: function (button) {
var input = document.createElement ('input');
input.type = 'hidden';
input.name = button.name;
input.value = button.value;
button.parentNode.insertBefore (input, button);
}
}
</ script>
Source: https://habr.com/ru/post/48381/
All Articles