0

I have inside the blade file a list of options and i'm trying to navigate the url that corresponds to the value selected. My code below doesn't work because i don't know how i'm gonna passe the value of the function to the route parameters because i have an error of

Undefined constant 'zone'.

How can i do that ?

<select name="zone" autocomplete="off" class="custom-select" id="s1" ss-deselect="true" onchange="updateZoneUrl(this.value)">
  <option data-placeholder="true">Zone</option>
    @foreach ($zones as $key => $zone)
      <option value="{{ $key }}">{{ $zone }}</option>
    @endforeach
</select>

<script>
  var updateZoneUrl = (zone) => {
    if (zone) {
      window.location.href = {{ route(Route::current()->getName(), ['zone' => zone]) }};
    }
  }
</script>
Abdo Rabah
  • 1,670
  • 2
  • 15
  • 31
  • Your function name is **updateZone**, and in the select you call **updateZoneUrl**. Are they different functions? – Atika Sep 08 '21 at 14:44
  • It would also be helpfull to know if it is PHP or JS throwing the error. Also which version of Laravel are you using? And I can strongly advice looking into VueJS in the future. – phn Sep 08 '21 at 15:12
  • @Atchiiii just a typo they are the same function – Abdo Rabah Sep 08 '21 at 15:15
  • You can check my [answer](https://stackoverflow.com/questions/69030834/redirect-to-route-inside-select-options-in-laravel/69032167#69032167) Tell me if this suits you. – Omarname Sep 08 '21 at 17:05

0 Answers0