I do not know much about web development and I'm kind of lost. I need to pass the id of a movie to a laravel route and I'm not sure how to get that value.
<select class="form-control" style="width: 20%" onchange="" id="select" name="filme">
<option value="" selected disabled>Selecione um filme</option>
@foreach($filmes as $f)
<option value="{{$f->id}}">{{$f->nome}}</option>
@endforeach
</select>
<?php echo $var = pegaId(); ?>
<br><br>
<button type="submit" class="w3-btn-block" onclick="window.location='/filmes/{{$var}}'">Ver eventos</button>
<script type="text/javascript">
function pegaId(){
return document.getElementById('select');
}
</script>
I've read that there is no way to assign the return of a JS function to a php variable because the JavaScript runs on the client side and PHP on the server side, so my variable does not recognize the function return at that time. Is that right?
When I call the function pegaId()
of the error
Call to undefined function pegaId ()
I believe I have an easier way to do this, like calling the JS function in my url but I'm not getting it: (