6

I am disabling my submit buttons when submitting a form, for preventing the user to submit the form multiple times.

$(function ()
{
    $("form").submit(function ()
    {
        $(":submit", this).attr("disabled", "disabled");
    });
});

But if the client validation fails I want to enable the button again. I am using asp.net mvc unobtrusive client validation

2 Answers 2

2

You can use the jQuery One event as detailed in this answer.

Most solutions to this issue revolve around testing $("form").valid() - you could probably use this in your function to determine whether to disable the submit button.

Sign up to request clarification or add additional context in comments.

1 Comment

If it is the only form on the page, there should be e global boolean variable "Page_IsValid" you can use to determine if the button should be disabled. The client side validation API is explained here: msdn.microsoft.com/en-us/library/…
0

You have to check if there is any error before disabling the submit button

$('#myform').submit(function () {
    if ($(this).find('.input-validation-error').length == 0) {
        $(this).find(':submit').attr('disabled', 'disabled');
    }
});

Hope it helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.