Ver Mensaje Individual
  #17 (permalink)  
Antiguo 29/11/2013, 10:39
oskar5
 
Fecha de Ingreso: abril-2008
Mensajes: 141
Antigüedad: 16 años
Puntos: 1
Respuesta: recuperar valores de campos SELECT anidados

Cita:
Iniciado por mortiprogramador Ver Mensaje
<saludos>
Ehm, veo que se han acalorado un poco, falta de birra!!
Ok, ok, te daré otra mano, pero con 2 condiciones
1. Que pongas el código en [HIGHLIGHT="PHP"][HIGHLIGHT="PHP"]highlight
2. Que indiques los nombres de los archivos que has publicado,
porque viendo las funciones js usas una página db.php y otra
NuevaEvaluacion.php, pero, las que publicaste con esas? o son otras?
Así que ordena el post, no tienes necesidad de otro, sino edita
el más reciente organizando todo, y empezamos a mirarlo
</saludos>

gracias men bueno pues los archivos son esos 2 precisamente

NuevaEvaluacion.php = donde se mostraria todo al usuario

db.php = donde esta el segundo select que AJAX llama a la primera pagina en algun elemento con un ID definido


Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.  
  4.     <script type="text/javascript">
  5.        
  6.         function showselect(str){
  7.             var xmlhttp;
  8.             if(str=="")
  9.               {
  10.                document.getElementById("txtHint").innerHTML="";
  11.                return;
  12.               }
  13.             if(window.XMLHttpRequest)
  14.               {
  15.                xmlhttp = new XMLHttpRequest;
  16.               }
  17.             else
  18.               {
  19.                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  20.               }
  21.             xmlhttp.onreadystatechange=function()
  22.               {
  23.                if(xmlhttp.readyState==4 && xmlhttp.status==200)
  24.                  {
  25.                   document.getElementById("preguntaselect").innerHTML=xmlhttp.responseText;
  26.                  }
  27.               }        
  28.             xmlhttp.open("GET","db.php?c="+str,true);
  29.             xmlhttp.send()
  30.            
  31.         }
  32.        
  33.        
  34.        
  35.        
  36.         function segundoslect(str){
  37.             var xmlhttp;
  38.             if(str=="")
  39.               {
  40.                document.getElementById("txtHint").innerHTML="";
  41.                return;
  42.               }
  43.             if(window.XMLHttpRequest)
  44.               {
  45.                xmlhttp = new XMLHttpRequest;
  46.               }
  47.             else
  48.               {
  49.                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  50.               }
  51.             xmlhttp.onreadystatechange=function()
  52.               {
  53.                if(xmlhttp.readyState==4 && xmlhttp.status==200)
  54.                  {
  55.                   document.getElementById("pruebas").innerHTML=xmlhttp.responseText;
  56.                  }
  57.               }        
  58.             xmlhttp.open("GET","NuevaEvaluacion.php?p="+str,true);
  59.             xmlhttp.send()
  60.            
  61.         }
  62.     </script>
  63.  
  64.  
  65. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  66. <title>Documento sin título</title>
  67. <style type="text/css">
  68. body,td,th {
  69.     font-family: Tahoma, Geneva, sans-serif;
  70.     color: #000;
  71. }
  72. #form1 table {
  73.     font-size: 16px;
  74. }
  75. #form1 table tr td h4 strong {
  76.     color: #FFF;
  77. }
  78. body,td,th {
  79.     font-family: Verdana, Geneva, sans-serif;
  80. }
  81. #textfield{
  82.    
  83.     height: 22px;
  84.     background: #cfcdcd;
  85.     border: solid medium #3f3f3f;
  86.     margin: -2px 0 0 0;
  87.     border-radius:4px;
  88.     padding:0 5px;
  89. }
  90. #button{
  91.     font-weight: bold;
  92.     width: 245px;
  93.     cursor: pointer;
  94.     padding: 8px;
  95.     margin: 0px 0px 0px 0px;
  96.     border: 1px solid #ccc;
  97.     background: #dadee3;
  98.     border-radius: 5px 5px 5px 5px;
  99. }
  100. #button:hover {
  101.     background: #d4e7ff;
  102. }
  103. #form1 table tr td h5 strong {
  104.     color: #FFF;
  105. }
  106. #form1 table tr td strong {
  107.     color: #FFF;
  108. }
  109. #form1 table {
  110.     font-size: 14px;
  111. }
  112. </head>
  113.  
  114. <?php
  115. include_once "conexion.php";
  116.  
  117. $p=$_GET['p'];
  118.  
  119. $miselect= 'SELECT Codigo, Nombre FROM Cuestionarios';
  120. $resul= mysql_query($miselect);
  121.  
  122.  
  123. $sqlpreg= "SELECT * FROM Respuestas WHERE CodPregunta = '$p'";
  124. $respreg= mysql_query($sqlpreg);
  125.  
  126. ?>
  127.  
  128. <form id="form1" name="form1" method="post" action="">
  129.  
  130. <table width="698" height="373" border="0" align="center">
  131.   <tr>
  132.     <td height="21" colspan="6" align="right"><button type="button" id="button" onclick="location.href = 'Administracion.php'" >Atras</button></td>
  133.   </tr>
  134.  
  135.   <tr>
  136.     <td height="21" colspan="6" id="pruebas">
  137.  
  138.     </td>
  139.   </tr>
  140.   <tr>
  141.     <td height="24" align="right"> Evaluación: </td>
  142.     <td colspan="4"><label for="select"></label>
  143.       <select name="selecteval" id="select" onchange="showselect(this.value)">
  144.             <?php
  145.                while($row = mysql_fetch_array($resul)) {
  146.                $CodEval = $row["Codigo"];
  147.                $nombre = $row["Nombre"];
  148.                echo "<option value=".$CodEval.">".$nombre."</option>";
  149.                 }
  150.              ?>
  151.        </select>
  152. </td>
  153.   </tr>
  154.   <tr>
  155.     <td width="115" height="24" align="right">Nueva Pregunta</td>
  156.     <td colspan="4"><textarea name="nuevapregunta" cols="35" id="textfield2"></textarea></td>
  157.   </tr>
  158.   <tr>
  159.     <td height="27" align="right"> Preguntas: </td>
  160.     <td colspan="2" id="preguntaselect">
  161.  
  162.     </td>
  163.     <td colspan="2"><input type="submit" name="button2" id="button" value="Agregar" />
  164.     </td>
  165.    
  166.   </tr>
  167.   <tr>
  168.     <td height="29" colspan="5" align="right" bgcolor="#FFFFFF">&nbsp;</td>
  169.     </tr>
  170.   <tr>
  171.     <td height="30" align="right" bgcolor="#EAEAEA">Respuesta: </td>
  172.     <td colspan="4" bgcolor="#EAEAEA"><input name="textfield2"  type="text" id="textfield" size="80" /></td>
  173.     </tr>
  174.   <tr>
  175.     <td height="34" align="right" bgcolor="#EAEAEA">&nbsp;</td>
  176.     <td colspan="2" bgcolor="#EAEAEA"><input type="checkbox" name="checkbox" id="checkbox" />
  177.       Respuesta Correcta. </td>
  178.     <td colspan="2" align="left" bgcolor="#EAEAEA"><input type="submit" name="button" id="button" value="Agregar respuesta a esta pregunta" /></td>
  179.    
  180.   </tr>
  181.   <tr>
  182.     <td  colspan="5" align="right">&nbsp;</td>
  183.     </tr>
  184.   <tr>
  185.     <td height="29" align="center" bgcolor="#333333"><strong>Opciones</strong></td>
  186.     <td width="231" align="center" bgcolor="#333333"><strong>Respuestas</strong></td>
  187.     <td width="80" align="center" bgcolor="#333333"><strong>Editar</strong></td>
  188.     <td width="146" align="center" bgcolor="#333333"><strong>Borrar</strong></td>
  189.     <td width="104" align="center" bgcolor="#333333"><strong>Flag</strong></td>
  190.    
  191.   </tr>
  192.             <?php
  193.                 while($row1 = mysql_fetch_array($respreg)) {
  194.                $resptas = $row1["Respuesta"];
  195.                          
  196.             ?>
  197.  
  198.   <tr>
  199.     <td height="24" align="center">1</td>
  200.     <td align="center"><?php echo $resptas; }   ?></td>
  201.  
  202.     <td align="center">&nbsp;</td>
  203.    
  204.   </tr>
  205.   <tr>
  206.  
  207.    
  208.   </tr>
  209. </form>
  210. </body>
  211. </html>




la otra pagina db.php


Código HTML:
Ver original
  1. <?php
  2. include_once "conexion.php";
  3.  
  4. ?>
  5.  
  6. <select name="selecteval" onchange="segundoslect(this.value)">
  7.  
  8. <?php
  9.  
  10. $q=$_GET['c'];
  11.  
  12.  
  13. $sqlselt= "SELECT * FROM Preguntas";
  14. $resul= mysql_query($sqlselt);
  15.  
  16. while($row = mysql_fetch_array($resul))
  17.     {
  18.      $Codpregta = $row["Cuestionario"];
  19.      $Pregunta = $row["Pregunta"];
  20.      $codgo = $row["Codigo"];
  21.         if($Codpregta==$_GET['c'])
  22.            {
  23. ?>
  24.              <option value="<?php echo $codgo; ?>"> <?php echo $Pregunta; ?> </option>
  25.              
  26.          <?php }
  27.    
  28.       } ?>
  29.    
  30.