I wish that when selecting the text of a radio button
the corresponding button is assigned or selected. The nomenclature is usually that the name that we assign to label for
must be the equivalent of the name of id
of input
.
But ... in a case automatically generated due to a query?
Muestro código:
//Si pulsamos el link "Eliminar opinión"...
if(isset($_GET["eliminar"])){
//Llamamos al método "obtenerOpinionesPorCliente" y le pasamos el parámetro del email del cliente.
$opiniones = BD::obtenerOpinionesPorCliente($cliente);
if($opiniones != null){
echo "<form action='menu_cliente.php?eliminar=1' name='form_a_eliminar' id='form_a_eliminar' method='POST'>";
$selected = true;
foreach ($opiniones as $opinion){
$fecha = new DateTime($opinion["fecha"]);
$comentario = $fecha->format('d/m/Y')."(".$opinion["idemail"].") - ".$opinion["opinion"]."<br/><br/>";
echo "<input type='radio' name='a_eliminar' value='".$opinion["idopinion"]."' ".($selected?"checked":"").">".$comentario."</input>";
//COMENTARIO!!! Que ID debo poner... para el label for...
$selected = false;
}
echo "<input type='submit' name='eliminar_opinion' id='eliminar_opinion' value='Eliminar opinión'>";
echo "</form>";
}else{
echo "<h1>¡No existen opiniones!</h1>";
echo "<img src='imagenes/advertencia.png' height='160px' width='220px' alt='Advertencia'>";
}
}