0

I'm using Laravel and inside a blade file i want to redirect to route each time an option is being selected. I tried the code below but it doesn’t redirect to the link when i select an option :

<select name="zone" autocomplete="off" class="custom-select">
  <option data-placeholder="true">Zone</option>
    @foreach ($zones as $key => $zone)
      <option value="{{ $key }}">
        <a href="{{ route(Route::current()->getName(), ['zone' => $zone]) }}">
          {{ $zone }}
        </a>
      </option>
    @endforeach
</select>
Abdo Rabah
  • 1,670
  • 2
  • 15
  • 31
  • 1
    Does this answer your question? [Redirect on select option in select box](https://stackoverflow.com/questions/7562095/redirect-on-select-option-in-select-box) – Wahyu Kristianto Sep 02 '21 at 13:15

2 Answers2

1

You cannot use links in select input. Instead use javascript like this:

<select onchange="window.location.assign('{{ url()->current().'?zone=' }}'+this.value)" name="zone" autocomplete="off" class="custom-select">
  <option data-placeholder="true">Zone</option>
    @foreach ($zones as $key => $zone)
      <option value="{{ $key }}">
        {{ $zone }}
      </option>
    @endforeach
</select>
Omarname
  • 21
  • 5
0

You need to make use of javascript or jquery here.

$('.custom-select').change(function(){
   //write you code here 
})
noushad mohammed
  • 375
  • 1
  • 4
  • 20