Marius Vasile

Marius Vasile

  • 602
  • 1.9k
  • 143.1k

asp.net core jquery if condition based on Model bool

Aug 27 2021 9:40 AM

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);
                }
            });
        });

 


Answers (1)