Tengo que agregar el valor de la fecha cuando hago clic en el hipervínculo en mi ruta, así que agrego así:
<div class="card-body"> <div class="form-group"> <label>Tanggal Awal:</label> <input type="date" class="form-control" id="exampleInputPassword1" placeholder="Masukkan Tanggal Lahir" name="tglawal" id="tglawal"> </div> <div class="form-group"> <label>Tanggal Akhir:</label> <input type="date" class="form-control" id="exampleInputPassword1" placeholder="Masukkan Tanggal Lahir" name="tglakhir" id="tglakhir"> </div> <a href="" onclick="location.href='/cetaklaporanpasien/'+document.getElementById('tglawal').value + '/' + document.getElementById('tglakhir').value " class="btn btn-block btn-primary border-0" style="background-color: #6998AB">Cetak</a> </div>
Mi Ruta:
Route::get('/cetaklaporanpasien/{tglawal}/{tglakhir}', 'LaporanController@cetakLaporanPasien')->name('cetaklaporanpasien');
Pero no se dirige a mi ruta. Entonces, ¿cómo agregar la ruta laravel con parámetro en onclick?
Intenta usar <button>
en lugar de <a>
Así que será así:
<button type="button" onclick="(your link)">Button</button>
Debería considerar usar una plantilla de hoja, ya que es una plantilla estándar de Laravel.
<div class="card-body"> <div class="form-group"> <label>Tanggal Awal:</label> <input type="date" class="form-control" id="exampleInputPassword1" placeholder="Masukkan Tanggal Lahir" name="tglawal" id="tglawal"> </div> <div class="form-group"> <label>Tanggal Akhir:</label> <input type="date" class="form-control" id="exampleInputPassword1" placeholder="Masukkan Tanggal Lahir" name="tglakhir" id="tglakhir"> </div> <a href="" onclick="cetakLaporan" class="btn btn-block btn-primary border-0" style="background-color: #6998AB">Cetak</a> </div> <script> let tglawal = document.getElementById('tglawal').value; let tglakhir = document.getElementById('tglakhir').value; function cetakLaporan(){ location.href = `/cetaklaporanpasien/${tglawal}/${tglakhir}` } </script>