I have a select and a textbox handled by a jquery. Basically, if I select a value from ddl, the textbox became disabled and if I enter text in the textbox, the ddl became disabled. The problem I have is: If the ddl is empty, the jquery does not work. How can I fix this?
- <div class="row no-gutters" onchange="funcLocation()">
- <div class="col-md-2">
- <label class="form-control text-white" style="background-color:mediumorchid;">Location </label>
- </div>
- @if (Model.RALocation == true)
- {
- <div class="col-md-3">
- <select id="LocS" class="form-control border-danger" asp-items="@Model.SelectLocation">
- <option value="">--Select Location--</option>
- </select>
- </div>
- <span class="text-danger ml-2 mr-2">OR</span>
- }
- <div class="col-md-3">
- <input id="LocT" class="form-control" placeholder="Enter New Location" />
- <input id="loc" asp-for="RiskAssessmentMain.Location" />
- </div>
- </div>
- function funcLocation() {
- var data1 = $("#LocS :selected").text();
- var data2 = $("#LocT").val();
- if (data2.length > 0) {
- $("#LocS").attr("disabled", true);
- $("#loc").val(data2);
- }
- else {
- $("#LocS").attr("disabled", false);
- }
- if (data1 != "--Select Location--") {
- $("#LocT").empty();
- $("#LocT").attr("disabled", true);
- $("#loc").val(data1);
- }
- else {
- $("#LocT").attr("disabled", false);
- }
- }