I am trying to create a system through listbox, that when selecting one, update the other.
One is EQUIPMENT and another is that of PLAYERS.
At the moment, I have a script with ajax
and an example in php, but it does not work for me
This is the ajax script
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#equipos').on('change',function(){
var equipos = $(this).val();
$.ajax({
type:"POST",
dataType:'json',
url : "prueba.php",
data : { opcion: equipos },
success: function(response){
alert("HOLA");
$("#jugadores").html(response);
},
error: function() {
alert('Error occured');
}
});
});
});
</script>
And here is the PHP example that I have at the moment, the equipment listbox if it updates, but the player listbox does not.
<?php
if(isset($_REQUEST["opcion"]))
{
$opciones = '<option value="0">"Elige el jugador"</option>';
$conexion = new mysqli("localhost","root", "", "dartsfusion");
$sqlCIU = "SELECT nom_j1, nom_j2, nom_j3, nom_j4, nom_j5, nom_j6, nom_j7, nom_j8 FROM equipos WHERE name_eq ='" . $_REQUEST['opcion'] . "'";
$resCIU = $conexion->query($sqlCIU);
while( $fila = $resCIU->fetch_array() )
{
$opciones.='<option value="'.$fila[0].'">'.$fila[0].'</option>';
}
// Liberar resultados
mysqli_free_result($resCIU);
// Cerrar la conexión
mysqli_close($conexion);
echo $opciones;
}
?>
<!-- html con los select box -->
<select name="equipos" id="equipos" class="form-control">
<option value="" selected>Elige equipo</option>
<?php
$conexion = new mysqli("localhost","root", "", "dartsfusion");
$acentos = $conexion->query("SET NAMES 'utf8'");
$sqlPROV = "SELECT id_eq, name_eq FROM equipos";
if ($resPROV = $conexion->query($sqlPROV))
{
while ($fila = $resPROV->fetch_row())
{
echo "<option value='" . $fila[0] . "' >" . $fila[1] . "</option>";
}
$resPROV->close();
}
?>
</select>
</div>
<div class="form-group">
<select name="jugadores" id="jugadores" class="form-control">
<option selected>Elige tu jugador</option>
</select>
</body>
</html>