简体   繁体   English

禁用提交按钮,直到完成所有字段

[英]Disable submit button until all the fields are complete

I am trying to disable the submit button until all the fields are completed. 我试图禁用提交按钮,直到所有字段都完成。 I have written a code for this but it isn't working. 我已经为此编写了代码,但无法正常工作。 The submit button is enabled all the time even if the values are not entered in the fields. 即使未在字段中输入值,也始终启用提交按钮。 Any help please? 有什么帮助吗? Below is the html code: 以下是html代码:

 $(document).ready(function () { validate(); $('#Quarter, #Year, #LineID').change(validate); }); function validate() { if ($('#Quarter').val()!="--Select Quarter--" && $('#Year').val()!="--Select Year--" && $('#LineID').val().length > 0 { $("input[type=submit]").prop("disabled", false); } else { $("input[type=submit]").prop("disabled", true); } } 
 <div class="row"> <div class="col-lg-8"> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-lg-4">Period:</label> <div class="col-lg-8"> @Html.DropDownList("Quarter", new SelectListItem[] { (new SelectListItem() { Text = "Q1", Value = "1" }), (new SelectListItem() { Text = "Q2", Value = "2" }), (new SelectListItem() { Text = "Q3", Value = "3" }), (new SelectListItem() { Text = "Q4", Value = "4" }) },"--Select Quarter--", new { @class = "form-control" }) <br /> @Html.DropDownList("Year", new SelectListItem[] { (new SelectListItem() { Text = "2016", Value = "2016" }), (new SelectListItem() { Text = "2017", Value = "2017" }) },"--Select Year--", new { @class = "form-control" }) </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-lg-4">Line ID:</label> <div class="col-lg-8"> @Html.TextBoxFor(model => model.floorConfig.LineID, new { onkeypress = "return isNumberKey(event)", @class = "form-control" }) </div> </div> </div> <div class="row"> <div class="col-lg-offset-4" style="padding: 10px 0px 0px 0px;"> <input type="submit" id="submit" value="Submit" class="btn btn-lg btn-success" /> <input type="button" id="btnCancel" value="Clear" class="btn btn-lg btn-success" /> </div> </div> </div> </div> 

Aren't you just missing the closing bracket from your IF statement? 您是否只是在IF语句中缺少结尾括号? JS Fiddle JS小提琴

I need to add id for Quarter and Year. 我需要为季度和年份添加id It works now! 现在可以使用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在引导模式中完成所有字段之前禁用提交按钮? - How do I disable the submit button until all fields are complete in a bootstrap modal? 禁用提交按钮,直到验证所有表单字段 - Disable Submit button until all form fields are validated Javascript:如何在所有字段都经过验证之前禁用提交按钮? - Javascript: How to disable submit button until all fields are validated? 我需要禁用提交按钮,直到所有字段都具有值 - I need to disable submit button until all the fields are having values 禁用提交按钮,直到填写输入字段 - Disable submit button until input fields are filled 禁用提交按钮,直到填写字段 - Disable Submit button until fields are filled in Javascript - 禁用提交按钮,直到3个字段不为空 - Javascript - Disable submit button until 3 fields are not empty 如何禁用提交按钮,直到所有文本字段都已填满并且选择了文件 - How to disable submit button until all text fields are full and file is selected 禁用jQuery的提交按钮,直到所有字段都具有值(输入,单选,选择,复选框) - Disable submit button with jQuery until all fields have values (input, radio, select, checkbox) 禁用表单提交按钮,直到填充所有输入/文本区域字段,而不使用 for 循环(无 jQuery) - Disable form submit button until all input/textarea fields are filled, without using for loop (no jQuery)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM