I have to add date value when i click hyperlink into my route, so i add like this:
<div >
<div >
<label>Tanggal Awal:</label>
<input type="date" id="exampleInputPassword1" placeholder="Masukkan Tanggal Lahir" name="tglawal" id="tglawal">
</div>
<div >
<label>Tanggal Akhir:</label>
<input type="date" 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 " style="background-color: #6998AB">Cetak</a>
</div>
My Route:
Route::get('/cetaklaporanpasien/{tglawal}/{tglakhir}', 'LaporanController@cetakLaporanPasien')->name('cetaklaporanpasien');
But it's doesn't directing into my route. So, how to add laravel route with parameter in onclick?
CodePudding user response:
Try using <button> instead of <a>
So it will be like this:
<button type="button" onclick="(your link)">Button</button>
CodePudding user response:
You should be considering to use blade template as it is laravel standart templating.
<div >
<div >
<label>Tanggal Awal:</label>
<input type="date" id="exampleInputPassword1" placeholder="Masukkan Tanggal Lahir" name="tglawal" id="tglawal">
</div>
<div >
<label>Tanggal Akhir:</label>
<input type="date" id="exampleInputPassword1" placeholder="Masukkan Tanggal Lahir" name="tglakhir" id="tglakhir">
</div>
<a href="" onclick="cetakLaporan" 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>
