0
I have a select that lists all my players:
<select name="jogador" id="cod_jogador">
<option name=""></option>
<?php foreach($jogadores as $jogador): ?>
<option id="codigo" value="<?= $jogador['cod_jogador']?>">
<?= $jogador['nome']?>
</option>
<?php endforeach; ?>
</select>
I want that when the user choose a player the variable $cod_player is filled with the value of that select, for that I made this script:
<script>
select = $('#cod_jogador');
select.bind("click", function(){
$.ajax({
url: 'idc-comparacao-jogador.php',
type: 'post',
dataType: 'html',
data: {
'codigo': $('#codigo').val()
}
}).done(function(data){
console.log(data);
$('#codigo').val('');
});
});
</script>
The problem is that on the date it returns the HTML code of the page and not the value of my value, could anyone help me? How do I pass the value of my option to my PHP
Use $('#player option:Selected'). val(); to get the value of the selected option
– Bruno Folle