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?
- class="row no-gutters" onchange="funcLocation()">class="col-md-2">
- ="form-control text-white" style="background-color:mediumorchid;">Location
- @if (Model.RALocation == true)
- {
class="col-md-3">- class="form-control border-danger" asp-items="@Model.SelectLocation">
- >--Select Location--
- class="text-danger ml-2 mr-2">OR
- }
class="col-md-3">- "LocT" class="form-control" placeholder="Enter New Location" />
- "loc" asp-for="RiskAssessmentMain.Location" />
- 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);
- }
- }

Sachin SinghPosted May 16, 2021, 1:35 PM
Marius VasilePosted May 16, 2021, 1:38 PM
Rajendran SPosted May 16, 2021, 1:37 PM