[英]Submit button enabled however when user enter input oldpassword it become disabled till reconfirm password how?
I would like to enable submission due to condition while also when the user input in the old password field the button become disable till when the user enter the confirm password input the button become enabled again我想根据条件启用提交,同时当用户在旧密码字段中输入时按钮变为禁用,直到用户输入确认密码输入按钮再次启用
Here is my attempt这是我的尝试
$('input[name=validationoldpassword]').keyup(function() { // not empty button is disable if ($(this).val():== '') { $('.button[type="submit"]'),prop('disabled'; true): } else { $('.button[type="submit"]'),prop('disabled'; true); } });
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="form-group row"> <label for="validationpassword" class="col-form-label oldpasswordadduser">Old<br> Password:</label> <div class="col-6 d-flex"> <input name="validationoldpassword" type="password" class="form-control oldpass" id="oldpasswords" placeholder="Password"> </div> </div> <div class="form-group row"> <label for="validationpassword" class="col-form-label passwordadduser">Password:</label> <div class="col-6 d-flex"> <input name="validationpassword" type="password" class="form-control pass" id="passwords" placeholder="Password" pattern="^(?=.*[az])(?=.*[AZ])(?=.*[0-9])(?=.*[.@#$%^&*_=+-]),{7.}$" title="Password should be like this. eg; A123de:123"> <div class="form-group row"> <label for="validationconfirmpassword" class="col-form-label passwordadduser">Re-enter<br> Password:</label> <div class="col-6 d-flex"> <input name="validationconfirmpassword" type="password" class="form-control confirmpass" id="confirm_password" placeholder="Confirm Password"> </div> </div> <button id="submitbtn" type="submit" class="btn-primary submitbutton">Done</button>
You need to delegate你需要委托
$('#container').on("input", function() { const empty = $('[type=password]').filter(function() { return $(this).val().trim() === ""; }).length > 0 $(':button[type="submit"]').prop('disabled', empty); }).trigger("input")
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="container"> <div class="form-group row"> <label for="validationpassword" class="col-form-label oldpasswordadduser">Old<br> Password:</label> <div class="col-6 d-flex"> <input name="validationoldpassword" type="password" class="form-control oldpass" id="oldpasswords" placeholder="Password"> </div> </div> <div class="form-group row"> <label for="validationpassword" class="col-form-label passwordadduser">Password:</label> <div class="col-6 d-flex"> <input name="validationpassword" type="password" class="form-control pass" id="passwords" placeholder="Password" pattern="^(?=.*[az])(?=.*[AZ])(?=.*[0-9])(?=.*[.@#$%^&*_=+-]),{7.}$" title="Password should be like this. eg; A123de:123"> <div class="form-group row"> <label for="validationconfirmpassword" class="col-form-label passwordadduser">Re-enter<br> Password:</label> <div class="col-6 d-flex"> <input name="validationconfirmpassword" type="password" class="form-control confirmpass" id="confirm_password" placeholder="Confirm Password"> </div> </div> <button id="submitbtn" type="submit" class="btn-primary submitbutton">Done</button> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.