Skip to content Skip to sidebar Skip to footer

Enable Submit Button If All Fields Filled

I have a form
Username Password .val()) { alert('Nothing is checked!'); } else { alert('One is checked'); }

Solution 2:

You need to use prop() and check the type. If the type is radio, you can add validation checks:

required = function(fields) {
  var valid = true;
  fields.each(function() { // iterate allvar $this = $(this);
    if ((($this.is(':text') || $this.is('textarea')) && !$this.val()) || // text and textarea
      ($this.is(':radio') && !$('input[name=' + $this.attr("name") + ']:checked').length)) { // radio
      valid = false;
    }
  });
  return valid;
}

validateRealTime = function() {
  var fields = $("form :input");
  fields.on('keyup change keypress blur', function() {
    if (required(fields)) {
      {
        $("#register").prop('disabled', false);
      }
    } else {
      {
        $("#register").prop('disabled', true);
      }
    }
  });
}

validateRealTime();
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><form>
  Username<br /><inputtype="text"id="user_input"name="username" /><br /> Password
  <br /><inputtype="password"id="pass_input"name="password" /><br /> Confirm Password<br /><inputtype="password"id="v_pass_input"name="v_password" /><br /> Email
  <br /><inputtype="text"id="email"name="email" /><br /><br/><textareaname="adress"id="adress"></textarea><br><inputtype="radio"name="gender"value="male"> Male
  <inputtype="radio"name="gender"value="female"> Female<br><inputtype="submit"id="register"value="Register"disabled="disabled" /></form>

Post a Comment for "Enable Submit Button If All Fields Filled"