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 when the user chooses a player to change $ cod_player to be filled with the value of that select, so 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