0
I don’t know much about web development and I’m a little lost. I need to pass the id of a movie to a route in Laravel and I’m not sure how to get this 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 read that there is no way to assign the return of a JS function to a php variable because Javascript runs on the client side and PHP on the server side, so my variable does not recognize the return of the function at that time. That’s 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 :(
Where does the information come from? is from
array de $filmes
? why what you did seems almost right but,{{$var}}
comes from where?– novic
is below select, I try to make a call to pegaId() function but error
Call to undefined function pegaId()
– Marcio