Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Adding a disabled attribute to options from one select field based on the value in another select field

I have two select option fields--one with the ID of determined and the other vehicle_type. Determined has 4 options--2 of which should disable the options in the vehicle_type select field. I added an alert() if one of the 2 options are selected and the script fires as it should, but it will not add the disabled attribute.

$(document).ready(function(){
    $('#determined').change(function(){
        if($(this).val() == 0 || $(this).val() == 3){
            alert('Yeah') /* This Works */
            $("#vehicle_type option[value='0']").prop('disabled',true);
        }else{
            $("#vehicle_type option[value='1']").prop('disabled',false);
        }
    });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select wire:model="determined" id="determined"
        name="determined">
    <option selected value>Please Select</option>
    <option value="0">Published HP Figure (DIN)</option>
    <option value="1">Measured with Dynojet+Dyno</option>
    <option value="2">Measured with Mustang Dyno</option>
    <option value="3">Measured with Engine Dynamometer Cell</option>
</select>

<select wire:model="vehicle_type" id="vehicle_type"
        name="vehicle_type">
    <option selected value>Please Select</option>
    <option value="0">Stick shift and 2WD vehicle</option>
    <option value="1">Automatic or 4WD Drive</option>
</select>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here I disable all options as per your comment

$(document).ready(function() {
  $('#determined').on("change", function() {
    const dis = $(this).val() == 0 || $(this).val() == 3;
    $("#vehicle_type option").prop("disabled",dis)
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<select wire:model="determined" id="determined" name="determined">
  <option selected value>Please Select</option>
  <option value="0">Published HP Figure (DIN)</option>
  <option value="1">Measured with Dynojet+Dyno</option>
  <option value="2">Measured with Mustang Dyno</option>
  <option value="3">Measured with Engine Dynamometer Cell</option>
</select>

<select wire:model="vehicle_type" id="vehicle_type" name="vehicle_type">
  <option selected value>Please Select</option>
  <option value="0">Stick shift and 2WD vehicle</option>
  <option value="1">Automatic or 4WD Drive</option>
</select>

but why not just hide?

$(document).ready(function() {
  $('#determined').on("change", function() {
    const dis = $(this).val() == 0 || $(this).val() == 3;
    $("#vehicle_type").toggle(!dis)
  }).change();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<select wire:model="determined" id="determined" name="determined">
  <option selected value>Please Select</option>
  <option value="0">Published HP Figure (DIN)</option>
  <option value="1">Measured with Dynojet+Dyno</option>
  <option value="2">Measured with Mustang Dyno</option>
  <option value="3">Measured with Engine Dynamometer Cell</option>
</select>

<select wire:model="vehicle_type" id="vehicle_type" name="vehicle_type">
  <option selected value>Please Select</option>
  <option value="0">Stick shift and 2WD vehicle</option>
  <option value="1">Automatic or 4WD Drive</option>
</select>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!