title: How to change value of input type field from clicked HTML row table?
body: <p>So here is my full code, i try to connect database with html table, and i'd like to change the value of input type with the data from the table :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;MAHASISWA&lt;/title&gt;
  &lt;link rel="shortcut icon" href="code.ico"&gt;
  &lt;style&gt;
    #data tr:hover{
      background-color: #aaa;
      cursor: pointer;
    }
    #data tr:nth-child(even){
      background-color: #ccc;
    }
    #data th{
      background: #fff;
    }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body style="background-color:cornsilk"&gt;
  &lt;form action="&lt;?php echo "mahasiswa.php"?&gt;" method="post"&gt;
    &lt;fieldset align="center" style="border:5px solid black;margin:0px 500px"&gt;
      &lt;legend&gt;Data&lt;/legend&gt;
      &lt;table&gt;
        &lt;tr&gt;
          &lt;td&gt;NIM&lt;/td&gt;
          &lt;td&gt;&lt;input min="0" type="number" name="nim"&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;Nama&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="nama"&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;Jurusan&lt;/td&gt;
          &lt;td&gt;&lt;select name="jurusan" style="width:173px"&gt;
            &lt;option value="Sistem Informasi"&gt;Sistem Informasi&lt;/option&gt;
            &lt;option value="Teknik Industri"&gt;Teknik Industri&lt;/option&gt;
            &lt;option value="Teknik Informatika"&gt;Teknik Informatika&lt;/option&gt;
            &lt;option value="Ilmu Komputasi"&gt;Ilmu Komputasi&lt;/option&gt;
            &lt;option value="Sistem Komputer"&gt;Sistem Komputer&lt;/option&gt;
          &lt;/select&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;input type="submit" name="submit" value="INPUT"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="button" name="update" value="DELETE" disabled&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="button" name="delete" value="UPDATE" disabled&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/fieldset&gt;
    &lt;/form&gt;
  
  &lt;table id="data" border="1" style="margin-top:50px" align="center"&gt;
    &lt;caption align="center"&gt;Tabel Data Mahasiswa&lt;/caption&gt;
    &lt;tr style="text-align:center"&gt;
      &lt;strong&gt;
      &lt;th width="150px"&gt;NIM&lt;/th&gt;
      &lt;th width="250px"&gt;Nama&lt;/th&gt;
      &lt;th width="250px"&gt;Jurusan&lt;/th&gt;
      &lt;/strong&gt;
    &lt;/tr&gt;
        &lt;?php
        $conn = mysqli_connect("localhost", "root", "root", "belajar");
        $query = "select * from mahasiswa";
        $result = mysqli_query($conn, $query);
        if($result){
          while($row = mysqli_fetch_row($result)){
            ?&gt;
            &lt;tr onclick="settext(this.index)"&gt;
              &lt;td&gt;&lt;?php echo $row[0]?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $row[1]?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $row[2]?&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;?php }
          mysqli_free_result($result);
          mysqli_close($conn);
        }
       ?&gt;
  &lt;/table&gt;
  &lt;script&gt;
    function settext(x) {
      var table = document.getElementById('id');
      var a = table.rows[x].cells[0].innerHTML;
      var b = table.rows[x].cells[1].innerHTML;
      var c = table.rows[x].cells[2].innerHTML;
      document.getElementByName('nim').value = parseInt(a);
      document.getElementById('nama').value = b;
      var opt = document.createElement('option');
      opt.value = c;
      opt.innerHTML = c;
      document.getElementById('jurusan').appendChild(opt);
    }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Is there a way by using javascript, to change the value of these 3 input types matching the clicked-row?</p>
  
  <p>P.S : Sorry for bad English</p>