[英]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>
I need to add id
for Quarter and Year. 我需要为季度和年份添加
id
。 It works now! 现在可以使用了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.