title: Pass Static Select Option Value to Laravel Controller using AJAX/Axios
body: <p>I want to call select option value into laravel condition and I want to know how to using it in my <code>create.blade.php</code>, here is the example:</p>
  <pre><code>@if (a is selected)
     // code goes here
  @endif
  </code></pre>
  <p><code>a</code> is select option value</p>
  <p>Currently, I'm using ajax to convert html value into php value but still not working.
  How do I pass it?</p>
  <hr />
  <p>Here's my select option code in <code>create.blade.php</code></p>
  <pre><code>&lt;div class=&quot;form-group&quot;&gt;
     &lt;p class=&quot;card-text&quot;&gt;Jenis Jadwal &lt;/p&gt;
     &lt;div class=&quot;&quot;&gt;
        &lt;select class=&quot;form-control&quot; id=&quot;frm-status&quot; name=&quot;status&quot;&gt;
           &lt;option value=&quot;&quot;&gt;PIlih&lt;/option&gt;
           &lt;option value=&quot;rutin&quot; {{ old('status') == 'rutin' ? 'selected' : '' }}&gt;Rutin&lt;/option&gt;
           &lt;option value=&quot;khusus&quot; {{ old('status') == 'khusus' ? 'selected' : '' }}&gt;Khusus&lt;/option&gt;
           &lt;option value=&quot;libur-tahunan&quot; {{ old('status') == 'libur-tahunan' ? 'selected' : '' }}&gt;Libur Tahunan&lt;/option&gt;
           &lt;option value=&quot;nge-plus&quot; {{ old('status') == 'nge-plus' ? 'selected' : '' }}&gt;Nge-plus&lt;/option&gt;
        &lt;/select&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Here's my ajax script in <code>create.blade.php</code></p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
  
              $(function() {
  
                  $('#colorpicker').farbtastic('#warna');
  
                  // run on change for the selectbox
                  $( &quot;#frm-status&quot; ).change(function() {
                      updateStatusDivs();
                  });
  
                  // handle the updating of the duration divs
                  function updateStatusDivs() {
                      // hide all form-duration-divs
                      $('.form-status-div').hide();
  
                      var divKey = $( &quot;#frm-status option:selected&quot; ).val();
                      var getStatus = null;
                      $('#divFrm'+divKey).show();
  
                      if (divKey === &quot;khusus&quot;) {
                          $('#divFrmtanggal').show();
                          $('#divFrmjadwal').show();
                          $('#divFrmcheckbox').hide();
                          getStatus = &quot;khusus&quot;
                      } else if (divKey === &quot;nge-plus&quot;){
                          $('#divFrmtanggal').show();
                          $('#divFrmcheckbox').show();
                          getStatus = &quot;nge-plus&quot;
                      } else if (divKey === &quot;libur-tahunan&quot;){
                          $('#divFrmtanggal').show();
                          $('#divFrmcheckbox').show();
                          getStatus = &quot;libur-tahunan&quot;
                      } else if (divKey === &quot;rutin&quot;){
                          getStatus = &quot;rutin&quot;
                      };
  
                      $.ajax({
                          url: '/jadwal/tablekaryawanajax',
                          type: 'POST',
                          data: {
                              name: getStatus
                          },
                          success: function(data) {
                              console.log(data);
                          },
                          error: function() {
                              console.log('error');
                          }
                      });
                  };
  
                  // run at load, for the currently selected div to show up
                  updateStatusDivs();
  
              });
  &lt;/script&gt;
  </code></pre>
  <p>Here's my route for <code>tablekaryawanajax</code> (other routes in this group doesn't matter so I exclude them)</p>
  <pre><code>Route::group(['prefix' =&gt; 'jadwal'], function () {
     Route::post('tablekaryawanajax', 'JadwalController@tablekaryawanajax')-&gt;name('jadwal.tablekaryawanajax');
  });
  </code></pre>
  <p>Here's my <code>tablekaryawanajax</code> function in <code>JadwalController.php</code></p>
  <pre><code>public function tablekaryawanajax(Request $request)
  {
     return view('Jadwal.karyawantable', compact('karyawan'));
  }
  </code></pre>