Home > Blockchain >  Disable dropdown menu items using JQUERY
Disable dropdown menu items using JQUERY

Time:03-25

I am using a dropdown menu to count working hours for the week. The problem I am facing is that once The weekly hours get to 37.5 I want to disable the options within the dropdown menu that would allow for the exceeding of 37.5. The dropdown menu increases by 15 minute intervals

For example if somebody has worked 37 hours already they will only be allowed to choose 30 mins from the dropdown menu, and all of the options that would exceed this are disabled/hidden what ever. I am using a counter to count the total hours worked in the week and trying to compare the total to the available dropdown options.

I have tried something like this without joy

 $("#workedHrs option").filter(function () {
                    if ($(this).val()   count > 2249)
                        console.log($(this).val()   count > 2249)                                     
                }).prop("disable", true)

CodePudding user response:

  • return instead of console.log
  • disabled not disable

let count = 30;
$("#workedHrs option").filter(function () {
    return ( $(this).val()   count) > 2249;           
}).prop("disabled", true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="workedHrs">
  <option value="1000">1000</option>
  <option value="3000">3000</option>
</select>

  • Related