i'm having a problem with the @foreach in a blade.view
<SELECT id= "chosen" type="text" class="form-control @error('chosen') is-invalid @enderror" name='chosen' style="width: 300px">
@foreach($tables as $chosen)
<option value="{{ $chosen }}" > {{ $chosen }}</option>
@endforeach
</SELECT>
{{ var_dump($chosen) }}
in this dropdown menu the var_dump() does not print the value of what i choose, just the last row of the foreach, how can i print the data i choose in the menu?
PHP runs from server and sent rendered html to client, so you cant access selected value in dropdown. you can use JQuery in browser to get current selected value.
check this:
$('#chosen').on('change', function() {
alert( this.value );
});
or
var selectedItem = $("#chosen").children("option:selected").val();
alert("You have selected the item- " + selectedItem);