Problem with disabling submit buttons on submit form

Hello

I am using jquery disable to submit the plugin, but I have a problem. If I disable the send buttons, they will not be sent back to the server, so I can’t say which button was pressed. This is normal? Anything I can do about it?

I really don't want to reconfigure my site, so I need to set a variable in the form view to indicate which button was clicked.

Any ideas?

+3
source share
4 answers

Here is the workaround I just found in the jQuery forum :

<script type="text/javascript">
    $(document).ready(function() {
        $("#sendSearch").click(function() {
            $('#loadingDiv').show();
            $('#sendSearch').attr("disabled", "disabled");

            // these two lines are the workaround
            this.form.submit();
            return true;
        });
    });
</script>
0
source

-

<button> , . .

+3

You can submit via jquery and disable the button:

<input type="submit" value="do it!" onclick="$('#mainform').submit(); $(this).attr('disabled','disabled' ); $('#pleasewait').show();" />

EDIT: I forgot form.submit () is not asynchronous. Instead, you can execute an ajax request:

$.ajax({
url: "someurl",
type:"POST",
cache: false,
dataType: "json",
success:gotIt,
async:true,
timeout:240000,
error:ajaxError,
data:$("#mainform").serialize()
}); 

or you can simply .hide () the button, or after clicking on it, set the inactive onClick () handler and stylize it to look disabled.

0
source

Be easier :)

var formid="#id-form-if-exists"; //Put here the id if exists
$("form"+formid).submit(function(){$("form"+formid+" input").attr("disabled",false);});

YES

0
source

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


All Articles