title: Laravel- Auto fill input after selecting value from dropdown
body: <p>how to do the auto fill after select the dropdown list. I'm not really good in js or ajax.
  When user select doc_no then both rev_no and title field must be filled up. Thanks!</p>
  
  <p>View</p>
  
  <pre class="lang-php prettyprint-override"><code>
   &lt;div class="form-group"&gt;
  {!! Form::label('text', 'Doc No', ['class' =&gt; 'col-lg-3 control-label']) !!}
  &lt;div class="col-lg-10"&gt;
  &lt;select name="docNo" id="docNo" class="form-control" style="width:250px"&gt;
  
  @foreach ($soplists as $soplist)
  &lt;option value="{{ $soplist-&gt;id }}"&gt;{{ $soplist-&gt;doc_no }}&lt;/option&gt;
  @endforeach
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  
  
  &lt;input type="hidden" name="carType" value="Internal Audit" class="form-control"&gt;
  
  &lt;div class="form-group"&gt;
  {!! Form::label('text', "Rev No", ['class' =&gt; 'col-lg-5 control-label']) !!}
  &lt;div class="col-lg-5"&gt;
  &lt;input type="text" class="form-control" id="rev" /&gt;
  
  &lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;div class="form-group"&gt;
  {!! Form::label('text', "Title", ['class' =&gt; 'col-lg-5 control-label']) !!}
  &lt;div class="col-lg-10"&gt;
  &lt;input type="text" class="form-control" id="title" /&gt;
  
  &lt;/div&gt;
  
  
  </code></pre>
  
  <pre><code>&lt;script&gt;
      $('#docNo').change(function() {
          var id = $(this).val();
          var url = '{{ route("getDetails", ":id") }}';
          url = url.replace(':id', id);
  
          $.ajax({
              url: url,
              type: 'get',
              dataType: 'json',
              success: function(response) {
                  if (response != null) {
                      $('#rev').val(response.rev_no);
                      $('#title').val(response.title);
                  }
              }
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller
  ---php</p>
  
  <pre><code>   public function getDetails($id = 0)
  {
      $data = sopList::where('doc_no', $id)-&gt;first();
      echo json_encode($data);
      exit;
  }
  </code></pre>
  
  <hr>
  
  <p>Route</p>
  
  <pre><code>
  'Route::get('get/details/{id}', 'internalAuditController@getDetails')-&gt;name('getDetails');'
  </code></pre>
  
  <p>Database sop_list table image link</p>
  
  <p><a href="https://ibb.co/SwkJhLc" rel="nofollow noreferrer">https://ibb.co/SwkJhLc</a></p>
  
  <p>Dropdown and input image</p>
  
  <p><a href="https://ibb.co/0VN3Z2y" rel="nofollow noreferrer">https://ibb.co/0VN3Z2y</a></p>
  
  <p>Network tab</p>
  
  <p><a href="https://ibb.co/56w5BLD" rel="nofollow noreferrer">https://ibb.co/56w5BLD</a></p>