Satya Teja
Satya Teja

Reputation: 616

How to disable submit button when validation fails and enable it back after it passes using validation.js?

I am using validate.js for validation in my site. so how can i disable submit button when validation fails and enable it back after it passes. i have tried it by adding following code to success callback

success: function(label) {
            label.html(" ").addClass("pop_valid");
            if($('#form').validate()){
                $('#submit -button').attr('disabled',false);
            }
        }

by this i am able to enable it when total form is valid but if after that some field was again changed and if form becomes invalid the how to disable it again? anyone can pls help me with this

Upvotes: 1

Views: 2162

Answers (1)

Ram Singh
Ram Singh

Reputation: 6918

Try the following code to disable the button

 $('[id$=helobtn]').attr("disabled", "disabled");

And to enable try the following:

$('[id$=helobtn]').removeAttr("disabled");

hope this will help you...........Or you can View this link to get what you require..

Updated I think you want to do it on Change the value. if so then you have to validate on blur for textboxes and Change for dropdown list like following: For text box

    $(document).ready(function () {
        $('[id$=test]').live('blur', function () {
            if (validate) {
                // enable btn 
            } else {
                // disable btn 

            }

        });


         });

For Dropdownlist

 $('[id$=test]').live('change', function () {
            if (validate) {
                // enable btn 
            } else {
                // disable btn 
            }
        });

Upvotes: 1

Related Questions