SALUDOS. GRACIAS.
Código php:
Ver original
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Sistema de encuesta</title> <script language="javascript" type="text/javascript" src="funciones_javascript.js"> <!-- function submitbutton_Poll1() { var form = document.frmencuesta; var radio = form.opcion; var radioLength = radio.length; var check = 0; for(var i = 0; i < radioLength; i++) { if(radio[i].checked) { form.submit(); check = 1; } } if (check == 0) { alert('Debe seleccionar una promoción para poder participar'); } } //--> </script> <link href="../estilos/css.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- body { background-color: #990000; } --> </style></head> <body> <?php require('conexion.php'); //consultamos si hay datos en la tabla if($cant['nroenc']==0){ echo "<p>No hay encuesta</p>"; echo "<p><a href=\"admin.php\">Agregar encuesta</p>"; }else{ //consultamos la encuesta actual //obtenemos los datos de la tabla $id=$datos['idenc']; $preg=$datos['pregunta']; $opc=$datos['opciones']; //empezamos a crear la estructura html echo '<br>'; echo " <center><span class='pregunta-encuesta'><p style=\text-align:center;\"><strong>".$preg."</strong></p></span></center> <div id=\"resultados\"> \n"; //especificamos un formulario echo " <form onsubmit=\"cargarResultados(); return false\" name=\"frmencuesta\" action=\"\"> <input type=\"hidden\" name=\"cod\" value=\"".$id."\" /> \n"; //especificamos opciones //NOTA, usamos explode para separar cada item por las comas $i=0; //contamos cuantas partes tiene opciones while($i<=$tot_elems-1){ $j=$i+1; //note que $opciones es un array y visualizamos sus elementos //mediante esta forma: elemento=$opciones[ubicacion_integer] echo " <p> <span class='opcion-encuesta'><input type=\"radio\" name=\"opcion\" value=\"".$j."\" id=\"opcion".$j."\" /> ".trim($opciones[$i])." </p></span> \n"; $i++; } echo " <input type=\"hidden\" name=\"nroopciones\" value=\"".$i."\" />"; echo " <p style=\"text-align:center;\"> <input class=\"boton\" type=\"submit\" value=\"Votar\" /> <button onclick='submitbutton_Poll1();'></button> </p> </form> </div>"; } ?> </body> </html>