title: How to enable disable option value in select based on condition PHP
body: <p>After user select location,in the next select option which is select car, will show list of car in selected location..The list of car retrieved direct from database..So i need to display all the car list in that area and need to disable enable the car list according the condition which is if the car id is not available the option value will disabled..and the option value become enable if car id is available..</p>
  
  <p></p>
  
  <pre><code>        &lt;?php
  
          $car = "SELECT *,location_master.location_id , location_master.location_name, 
          appcarinfo.loc_id_ext, appcarinfo.location ,appcarinfo.model ,appcarinfo.noplat FROM location_master 
         INNER JOIN appcarinfo ON
          appcarinfo.lat = location_master.gmaplat
          AND
          appcarinfo.lon = location_master.gmaplng
          where appcarinfo.model='".$fetchres['idmodel']."'  ";
  
          $qcar = mysqli_query($conn, $car);
          ?&gt;
         &lt;option disabled value="" selected hidden&gt;Please Select Car&lt;/option&gt;
          &lt;?php
          while ($showcar= mysqli_fetch_array($qcar))
          {
  
  if ($showcar['car_id']=="Available")
  {     
  ?&gt;
          &lt;option  class="&lt;?php echo $showcar['lon']; ?&gt;" value="&lt;?php echo $showcar['car_id']; ?&gt;" enabled&gt; &lt;?php echo $fetchres['maker'].' '.$fetchres['model_name'].'-'.$showcar['noplat'].' ' .$showcar['location_name']; ?&gt;&lt;/option&gt;
  
           &lt;?php
    }
   else
   ?&gt; &lt;option  class="&lt;?php echo $showcar['lon']; ?&gt;" value="&lt;?php echo        $showcar['car_id']; ?&gt;" disabled&gt; &lt;?php echo $fetchres['maker'].'      '.$fetchres['model_name'].'-'.$showcar['noplat'].' '     .$showcar['location_name']; ?&gt;&lt;/option&gt;
    &lt;?php
               }
            ?&gt;
          &lt;/select&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/CQJFE.png" rel="nofollow noreferrer">SELECT OPTION</a></p>
  
  <p>I'm also new to AJAX..how to pass data and retrieve it back to select option</p>
  
  <pre><code> //check availability car
  function check_availability() 
  {
      //id from form
      var reservation1 = document.getElementById("reservation");
      var pickup_date = document.getElementById("pickup_date").value;
      var return_date = document.getElementById("return_date").value;
      var pickup_time = document.getElementById("pickup_time").value;
      var return_time = document.getElementById("return_time").value;
      var carID= document.getElementById("carID").value;
              $.ajax({
                  type : "POST",
                  url : "function/check_car_availability.php",
                  data : {
                      pickup_date : pickup_date,
                      return_date : return_date,
                      pickup_time : pickup_time,
                      return_time : return_time,
                      carID : carID,
  
                  },
                  dataType : "JSON",
                  success : function(data) {
                      $('#edt_pickup').val(data.edt_pickup);
                      $('#edt_return').val(data.edt_return);
                      $('#msgCheck').html(data.msgCheck);
                      $('#btn_proceed').html(data.btn_proceed);
  
                  }
              }); 
  }
  </code></pre>
  
  <p>check_car_availability.php</p>
  
  <pre><code>      &lt;?php
  if ($_POST['pickup_date']) 
  {
  $pickup_date = $_POST['pickup_date'];
  $return_date = $_POST['return_date'];
  $pickup_time = $_POST['pickup_time'];
  $return_time = $_POST['return_time'];
  $car_id = $_POST['car_id'];
  $owner_id = $_POST['owner_id'];
  
  //convert normal date to epoch
  $pickup_date1 = explode("/",$pickup_date);
  $return_date1 = explode("/",$return_date);
  $pickup_time1 = explode(":",$pickup_time);
  $return_time1 = explode(":",$return_time);
  
  //hour, minute, second, month, day, year
  $edt_pickup = mktime($pickup_time1[0],$pickup_time1[1],0,$pickup_date1[1],$pickup_date1[0],$pickup_date1[2]);
  $edt_return = mktime($return_time1[0],$return_time1[1],0,$return_date1[1],$return_date1[0],$return_date1[2]);
  
  //convert from d/m/Y to Y-m-d
  $pickup_date_2 = $pickup_date1[2]."-".$pickup_date1[1]."-".$pickup_date1[0];
  $return_date_2 = $return_date1[2]."-".$return_date1[1]."-".$return_date1[0];
  
  //keluarkan tarikh yg customer pilih ada tak dlm booking master
  $chkBooked = mysqli_query($conn, "SELECT count(car_id) AS countid FROM appbooking WHERE 
  ((start_rent &gt;= '$edt_pickup' AND end_rent &lt;= '$edt_return') 
  OR (((start_rent &lt;= '$edt_pickup' AND end_rent &gt;= '$edt_return')))
  OR (((end_rent &gt;= '$edt_pickup' AND end_rent &lt;= '$edt_return')))
  OR (((start_rent &gt;= '$edt_pickup' AND start_rent &lt;= '$edt_return'))))  AND car_id = '$car_id'  AND status !='0'");
  $fetchBooked = mysqli_fetch_array($chkBooked);
  
  if($fetchBooked['countid'] != 0) //kalau ada show not available
  {   
      $availability = "Not Available";
      $available_count = 0;
  } else //kalau tak de show available
  {
      $availability = "Available";
      $available_count = 1;
  } 
  
  //keluarkan car details
  $carDetails = mysqli_query($conn, "SELECT * FROM appcarinfo WHERE car_id = '$car_id'");
  $fetchchkowner = mysqli_fetch_array($carDetails);
  
  
  
  //kalau manual availability check ada tak date dlm range yg owner dah set
  $sql = mysqli_query($conn, "SELECT count(car_availability.availability_id) AS cntAvail FROM appcarinfo INNER JOIN car_availability ON car_availability.car_id = appcarinfo.car_id WHERE appcarinfo.car_id = '$car_id' AND car_availability.start_available &lt;= '$edt_pickup' AND car_availability.end_available &gt;= '$edt_return'");
  $fetch = mysqli_fetch_array($sql);
  
  if ($fetchchkowner['custom_availability'] == 1) //if owner set manual availability
  {
      if ($fetch['cntAvail'] &gt; 0) //kalau ada 
      {
          $avail = 1;
      } else //kalau tak de
      {
          $avail = 0;
      }
  } else //if owner set auto availability
  {
      $avail = 1;
  }
  
  //check if this is klezcar car
  if($fetchchkowner["owner_id"] == "0")
  {
      $klezcar_loc_id = $fetchchkowner["loc_id_ext"]; 
  
      //check availability for blocked date klezcar
      $sqlBlock = "SELECT * FROM `blocked_date_klezcar` where (
                  ('".$pickup_date_2."' &gt; startdate and '".$pickup_date_2."' &lt; enddate)
                  or ('".$return_date_2."' &gt; startdate and '".$return_date_2."' &lt; enddate)
                  or ('".$pickup_date_2."' = startdate)
                  or ('".$return_date_2."' = enddate)
                  or ('".$return_date_2."' = startdate)
                  or ('".$return_date_2."' = enddate)
                  ) and (location=0 or location=".$klezcar_loc_id.") order by location desc limit 1";
      $queryBlock = mysqli_query($conn,$sqlBlock);
      if(mysqli_num_rows($queryBlock) &gt; 0)
      {
          $resBlock = mysqli_fetch_object($queryBlock);
          $avail = 0;
          $klezcar_blocked = 1;
          $klezcar_blocked_reason = $resBlock-&gt;reason;
      }
      else
      {
          $klezcar_blocked = 0;
      }
   }
  
  //calculation price rate
  include 'calculation_price/calculationprice.php';
  
  $encry = md5($edt_pickup.$edt_return.$total_pay.$total_rate.floor($day).$bhourplus.$car_id.$owner_id.$secretAuth);
  
  //combine appbooking &amp; car availability variable
  if ($avail == 1 &amp;&amp; $available_count == 1) 
  {
      $availStatus = "&lt;div class='alert alert-success'&gt;You are good, car available.&lt;br&gt;Rental Price : Total &lt;span style='font-size:20px; font-weight: bold;'&gt;".number_format($total_pay,2)."&lt;/span&gt; for ".floor($day)." day(s) ".$bhourplus." hour(s)&lt;/div&gt;";
      $btn_proceed = "&lt;a href='confirmbooking.php?pickupdate=".$edt_pickup."&amp;returndate=".$edt_return."&amp;totalpay=".$total_pay."&amp;totalrate=".$total_rate."&amp;bookday=".floor($day)."&amp;bookhour=".$bhourplus."&amp;carid=".$car_id."&amp;ownerid=".$owner_id."&amp;encry=".$encry."' class='btn btn-primary'&gt;Proceed&lt;/a&gt;";
  } else
  {
      $availStatus = "&lt;div class='alert alert-danger'&gt;We are sorry, car not available. Please refer Available &amp; Not available date table.&lt;/div&gt;";
      $btn_proceed = "";
      if($klezcar_blocked === 1)
      {
          $availStatus = "&lt;div class='alert alert-danger'&gt;".$klezcar_blocked_reason."&lt;/div&gt;";
          $btn_proceed = "";
      }
  }
      /* *** SPECIAL FOR RAYA 2019 *** */
      $start_blocked_date = "2019-06-04";
      $end_blocked_date   = "2019-06-09";
  
  
      if(  ($pickup_date_2 &gt;= $start_blocked_date  &amp;&amp; $pickup_date_2 &lt;= $end_blocked_date) 
        || ($return_date_2 &gt;= $start_blocked_date  &amp;&amp; $return_date_2 &lt;= $end_blocked_date)
        || ($pickup_date_2 == $start_blocked_date)
        || ($return_date_2 == $end_blocked_date)
        || ($return_date_2 == $start_blocked_date)
        || ($return_date_2 == $end_blocked_date))
      {
          $availStatus = "&lt;div class='alert alert-danger'&gt;The date has been marked as Hari Raya Aidlifitri holiday session. We accept minimum rental of 7 days and above only. Please re-select date at least 3/6/2019 - 10/6/2019.&lt;/div&gt;";
           $btn_proceed = "";
      }
      /* *** SPECIAL FOR RAYA 2019 *** */
  
  //return value
  $data['edt_pickup'] = $edt_pickup;
  $data['edt_return'] = $edt_return;
  $data['msgCheck'] = $availStatus;
  $data['btn_proceed'] = $btn_proceed;
  $data['total_rate'] = $total_rate;
  $data['total_pay'] = $total_pay;
  $data['no_day_booking'] = floor($day);
  $data['no_hour_booking'] = $bhourplus;
  
  echo json_encode($data);
  }
  ?&gt;
  </code></pre>