I have two situation where either data exists or have to be manually entered. I want to be able to disable or enable button based on text value lenght
View
<div class="row no-gutters mb-2"> <div class="col-md-1"> <label class="form-control text-white" style="background-color:indigo">Activity:</label> </div> @if (Model.JSAActivity != null) { <div class="col-md-3"> <span id="InpAct1" class="form-control">@Html.DisplayFor(model => model.JSAActivity)</span> </div> } else { <div class="col-md-3"> <input id="InpAct2" class="form-control" asp-for="JSASecondary.ActivitySec" /> </div> } </div>
jquery
$(function () { $("#DivAddData").on("change", function () { var minLenght = 3; var ia1 = $("#InpAct1").val().length; var ia2 = $("#InpAct2").val().length; var hd = $("#hazDetail").val().length; var ic = $("#InpCont").val().length; var ir = $("#InpResp").val().length; if (ia1 > minLenght || ia2 > minLenght && hd > minLenght && ic > minLenght && ir > minLenght) { $("#btnSubmitAD").attr("disabled", false); } else { $("#btnSubmitAD").attr("disabled", true); } }); });