title: How do I take variables in javascript?
body: <p>I made an AJAX request so that when I select drop down the results will be out. I am confused. The problem is that only a table is displayed. How come the data comes from the variable <code>$grade</code> (calculation of grade), the variable <code>$value</code> (calculation of total value)?</p>
  
  <p>I try to get the element. <code>$grade</code> instead it is undefined</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function(){
          $('#kategori').on('change', function(e){
              var id = e.target.value;
              $.get('/khs/khs_semester/' + id, function(data){
                  console.log(id);
                  console.log(data);
                  $('#khs').empty();
                  $.each(data, function(index, element){
                      $('#khs').append("&lt;tr&gt;&lt;td&gt;" + element.kode_mk + "&lt;/td&gt;&lt;td&gt;" + element.nama_mk + "&lt;/td&gt;" + "&lt;td&gt;" + element.semester + "&lt;/td&gt;&lt;td&gt;" + element.jml_sks + "&lt;/td&gt;&lt;td&gt;" + element.$grade + "&lt;/td&gt;&lt;/tr&gt;");
                  });
              });
          });
      });
  &lt;/script&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table class="table table-bordered"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th width="100"&gt;KODE MK&lt;/th&gt;
              &lt;th width="350"&gt;NAMA MK&lt;/th&gt;
              &lt;th width="50"&gt;SEMESTER&lt;/th&gt;
              &lt;th width="50"&gt;SKS&lt;/th&gt;
              &lt;th width="50"&gt;GRADE&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody id="khs"&gt;
          @foreach($mahasiswa as $row)
              @php
  
                  $nilai = hitung_nilai($row-&gt;id);
                  $grade = hitung_grade($nilai);
                  $mutu  = hitung_mutu($grade);
  
              @endphp
              &lt;tr&gt;
  
                  &lt;td&gt;{{ $row-&gt;kode_mk }}&lt;/td&gt;
                  &lt;td&gt;{{ $row-&gt;nama_mk }}&lt;/td&gt;
                  &lt;td&gt;{{ $row-&gt;semester }}&lt;/td&gt;
                  &lt;td&gt;{{ $row-&gt;jml_sks}}&lt;/td&gt;
                  &lt;td&gt;{{ $grade }}&lt;/td&gt;
                  &lt;td&gt;{{ $mutu*$row-&gt;jml_sks }}&lt;/td&gt;
              &lt;/tr&gt;
              @php
                  $totalSKS=$totalSKS+$row-&gt;jml_sks;
                  $totalMutu = $totalMutu+$mutu*$row-&gt;jml_sks;
              @endphp
          @endforeach
      &lt;/tbody&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/WDXPZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WDXPZ.png" alt="Error, Undefined"></a></p>