Click here to Skip to main content
16,020,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to enable form elements when selecting the first drop down with id LId3, I took the code from a button. The problem starts when I enable the searchable dropdown, when i open the searchable dropdown the form elements are not enabled. When the dropdown is clickable the form elements get enabled. Please assist with the below:
 
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<form asp-controller="Leaves" asp-action="Create" method="post" class="form-horizontal" role="form">
<div asp-validation-summary="ModelOnly"></div>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<div class="form-group" style="display: flex">

<script type="text/javascript">$(document).ready(function () {
$("#GFG :input").prop("disabled", true);
});

function enable_disable() {
$("#GFG :input").prop("disabled", false);
}</script>

<input class="form-control col-sm-2" data-toggle="tooltip" data-placement="left" title="Employee Identiy Number" readonly />

<div class="col-sm-3">
<select onclick="enable_disable()"
class="form-control" value="Enable"
id="LId3">
</select>
</div>
</div>

</form>
<form asp-controller="Leaves" asp-action="Create" method="post" class="form-horizontal" role="form" id="GFG">
<div asp-validation-summary="ModelOnly"></div>
<div class="form-group" style="display: flex">

<input class="form-control col-sm-2" value="Name" data-toggle="tooltip" data-placement="left" title="Name of employee" readonly />

<div class="col-sm-3">
<select asp-for="LId" id="LId1"
class="form-control"
asp-items="@(new SelectList(ViewBag.ListOfTable,"LId", "EmpName"))">
</select>
</div>
</div>


<div class="form-group" style="display: flex">

<input class="form-control col-sm-2" disabled value="Surname" data-toggle="tooltip" data-placement="left" title="Surname of employee" readonly />

<div class="col-sm-3">

<select asp-for="LId" id="LId2"
class="form-control"
asp-items="@(new SelectList(@ViewBag.ListOfTable,"LId", "EmpSurname"))">
</select>
</div>
</div>

<div class="form-group" style="display: flex">

<input class="form-control col-sm-2" value="Type of Leave" readonly />

<div class="col-sm-3">
<select asp-for="TypeOfLeave" name="offer" id="leave" class="form-control">
<option value="0">Select</option>
<option value="Sick">Sick</option>
<option value="Family Responsibility">Family Responsibility</option>
<option value="Study">Study</option>
<option value="Vacation">Vacation</option>
<option value="Bereavement">Bereavement</option>
<option value="TimeOffWithoutPay">Time Off Without Pay</option>
<option value="Military">Military</option>
<option value="JuryDuty">Jury Duty</option>
<option value="Maternity/Paternity">Maternity/Paternity</option>
<option value="Other">Other</option>

</select>
<span asp-validation-for="TypeOfLeave" class="text-danger"></span>
</div>
</div></form>


What I have tried:

I have only tried removing the searchable dropdown and using the normal dropdown.
Posted
Updated 17-Jan-20 10:21am
Comments
tninis 17-Jan-20 3:44am    
you want the elements to be enabled when you select an option from dropdown with LId3?
Member 10928805 17-Jan-20 3:46am    
yes
tninis 17-Jan-20 4:30am    
try this and remove the onclick="enable_disable()" from dropdown list
$('#LId3').change(function() {
$("#GFG :input").prop("disabled", false);
});
Member 10928805 17-Jan-20 4:37am    
still it is not working when selecting the searchable drop down
tninis 17-Jan-20 5:02am    
just tested on codepen, and when i am selection an option the inputes get enabled, show me what you did.

1 solution

I have bootstrap multiselect drop-down. I used following code to enable/disable element on page for specific drop-down value selection.

JavaScript
$("#drpList").change(function () {
            var selection = $('#drpList option:selected');
            var selected = [];
            $(selection).each(function(index, brand){
                selected.push([$(this).val()]);
                alert(selected);
                if (selected == 123) {
                    $("#txtComment").prop('disabled', true);
                }
                else {
                    $("#txtComment").prop('disabled', false);
                }
            });
        });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900