title: How to disable/enable select according to the checkbox value
body: <p>I have a form with a checkbox and select. I want to disable/enable select according to the checkbox value. I already have the if-else but I do not know how to disable/enable the select. I have tried a few codes but they are not working for me.</p>
  
  <p>I have tried the below code but still cannot disable/enable the select option. My checkbox id is Checkbox and select id is trip members. I want if the checkbox value is 'individual' the select is disabled else enable</p>
  
  <pre><code>$('#Checkbox').on('change', 'input[type=checkbox]', function() {  
  
     var value = $(this).val();
  
  
     if(value == 'group') {
       $('#trip_members').prop('disabled', false);
     }else if(value == 'individual') {
      $('#trip_members').prop('disabled', true);
     }else if(value == '') {
      $('#trip_members').prop('disabled', false);
     }
  });
  </code></pre>
  
  <p>My select option is like below. Is it because the id in the php the jquery cannot detect it ? </p>
  
  <pre><code>    &lt;label&gt;Trip Members&lt;/label&gt;&lt;br&gt; 
  
                   &lt;?php
                  $query = "SELECT ud.u_name,u.u_id FROM tbl_user_details as ud , tbl_user as u WHERE u.u_id = ud.u_id AND u.active=1 AND (u.g_id = 1 OR u.g_id = 2 OR u.g_id = 3 OR u.g_id = 4 OR u.g_id = 5)";
  
                  // Successful query?
                      if($result = mysqli_query($conn,$query))  {
                  // If there are results returned, prepare combo-box
                      if($success = mysqli_num_rows($result) &gt; 0) {
                      echo "&lt;select class='form-control' id='trip_members' name='trip_members[]' multiple&gt;";
                  // For each item in the results...
                      while ($row = mysqli_fetch_array($result))
                      // Add a new option to the combo-box
  
                      if (in_array($row['u_id'],$retrieved_majors2))
                      {
                         echo "&lt;option value='$row[u_id]' selected&gt;$row[u_name]&lt;/option&gt;";
  
                      }else{
                          echo "&lt;option value='$row[u_id]'&gt;$row[u_name]&lt;/option&gt;";
                      }
  
                      // End the combo-box
                       echo "&lt;/select&gt;";
                      }
                  // No results found in the database
                      else { echo "No results found."; }
                      }
               // Error in the database
                      else { echo "Failed to connect to database."; }
                  ?&gt;  
  </code></pre>
  
  <p>My checkbox code is like below</p>
  
  <pre><code>&lt;div class="col-md-6 col-sm-12 col-xs-12 form-group"&gt;
                  &lt;label&gt;Type:&lt;/label&gt;&lt;br&gt;    
                   &lt;div id="Checkbox"&gt;
                  &lt;label&gt;&lt;input type="checkbox" &lt;?php if($row_RecListMileage['type'] == "individual") echo "checked='checked'"; ?&gt;  
                  value="individual" name="type" id="type"&gt; Individual&lt;/label&gt;  
  
                  &lt;label&gt; &lt;input type="checkbox" &lt;?php if($row_RecListMileage['type'] == "group") echo "checked='checked'"; ?&gt; 
                   value="group" name="type" id="type"&gt; Group&lt;/label&gt;           
                   &lt;/div&gt;
                   &lt;/div&gt;
  </code></pre>