1

I have a jquery toggling menu with password fields. By default, the submit button is disabled, and enabled on keyup events.

$(function(){
  $("#submitProfile").attr("disabled","true");
  $("#password_confirmation, #password, #current_password").keyup(function(){
    $("#submitProfile").removeAttr("disabled");
  });
});

But how can I keep the button disabled until all the fields are filled?

2 Answers 2

4

You can add a condition.

$(function(){
  $("#submitProfile").attr("disabled","true");
  $("#password_confirmation, #password, #current_password").keyup(function(){
      if($("#password_confirmation").val() && $("#password").val() && $("#current_password").val())
          $("#submitProfile").removeAttr("disabled");
  });
});

Live demo

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

Comments

1

You can try something like this:-

if($('#password_confirmation, #password, #current_password').val().length>0){
 $("#submitProfile").removeAttr("disabled");
}

1 Comment

Did you try your code? Your solution doesn't work on this fiddle

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.