0
The page receives a value for $_GET and would like to auto select the value of a select input equal to the value of $_GET received using Jquery:
<?php
$valor = $_GET['valor']; // valor1
?>
<select name='selectValores'>
<option value='valor1'>Valor-1</option>
<option value='valor2'>Valor-2</option>
<option value='valor3'>Valor-3</option>
</select>
<script>
$(document).ready(function() {
});
</script>
RESOLVED:
<script>
$(document).ready(function() {
var theValue = '<?php echo $_GET['pesquisa-tipo']; ?>';
$('#formCaminhaoPesquisa #pesquisaTipo option[value=' + theValue + ']').attr('selected',true);
});
</script>
Wouldn’t it be better to do this directly in PHP? So the option is already selected without the need to use jQuery.
– Sam
Not because I need to manipulate DOM and I can’t change PHP unfortunately rsrsrs
– ElvisP