如何将变量从PHP的while循环传递给JavaScript

please help me. windows.location is working, but $id & $waktu only get the last value. not get from the selected. thanks alot.

While loop for :

<?php
  $tampil=mysql_query
  ("SELECT * FROM ms_modul");
   while($row=mysql_fetch_array($tampil))
     {
       $id  = $row['noid_modul'];
       $judul   = $row['judul_modul'];
       $waktu   = $row['waktu'];
       $waktuMenit  = $waktu/60; 
       echo $judul 
       echo $waktuMenit; echo " menit"; ?>

<input id="test" value="?module=quizcek&id=<?php echo $id ?>&waktu=<?php echo $waktu; ?>" >
<button class="btn btn-success" onclick="sweet()" id="btnShowAlert">Mulai Quiz</button>

        <?php } ?>

javascript:

<script>
  function sweet (){
  var ambil = document.getElementById('test').value;
  swal({
  title: 'Mulai mengerjakan quiz?',
  text: '',
  type: 'warning',
  showCancelButton: true,
  confirmButtonText: 'Ya',
  cancelButtonText: 'batal',
  confirmButtonClass: "btn btn-success",
  cancelButtonClass: "btn btn-danger",
  buttonsStyling: false
  }).then(function() {                  

  window.location=ambil
  }, function(dismiss) {
   // dismiss can be 'overlay', 'cancel', 'close', 'esc', 'timer'                  
  })
  }
</script>

</div>