I want to passing a variable (id) from view to controller using javascript onChange. I have done it but the result when I'm do dd always the same. In my case i always get "7".
Here is my code:
View:
<select id="jurusan_id" type="text" name="jurusan_id" onchange="filterJurusan()">
<option value disable>Jurusan</option>
@foreach (App\Models\Admin\Jurusan::all() as $jurusan)
<option value="{{ $jurusan->id }}">{{ $jurusan->nama_jurusan }}</option>
@endforeach
</select>
Route:
Route::get('datasiswa/{id}', 'Admin\SiswaController@filterSiswa')->name('filterSiswa');
Js:
function filterJurusan() {
window.location.href = "{{ route('filterSiswa', $jurusan->id) }}";
}
Controller:
public function filterSiswa(Request $request, $id)
{
dd($id);
}
I know something was wrong with my code, but i can't figure out what it is.