Ver Mensaje Individual
  #5 (permalink)  
Antiguo 29/11/2013, 11:57
oskar5
 
Fecha de Ingreso: abril-2008
Mensajes: 141
Antigüedad: 16 años
Puntos: 1
Respuesta: Super problema ajax

ok recapitulando

de nuevo explico, tengo:
2 campos selects anidados uno responed al otro mediante consultas y BD
eso funciona, ahora bien:
deseo realizar
1 - tabla generada con datos de Mysql pero quiero consultar esos datos en base al valor seleccionado del segundo campo SELECT

no me pasen mas pagians de como hacer los selects anidados porfavor que ya estan hecho y funcionando lo que necesito es lo d la tabla y para ello entiendo que debo capturar el valor del VALUE OJO el valor de la seleccion q se le haga para poder comprar ese bendito valor en una consulta

muchas gracias la verdad no seguire rogando ni molestando mas a los expertos en este foro pues al parecer mi solicitud de ayuda ha provocado molestias pero en realidad digo la verdad si uno sabe algo en la vida y quiere ayudar a alguien lo hace sin mas y si no sabe pss se queda callado o no?.

gracias.

NuevaEvaluacion.php = donde se mostraría todo al usuario

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.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.  
  5.  
  6.     <script type="text/javascript">
  7.  
  8.        function showselect(str){
  9.  
  10.             var xmlhttp;
  11.  
  12.             if(str=="")
  13.  
  14.               {
  15.                document.getElementById("txtHint").innerHTML="";
  16.                return;
  17.  
  18.               }
  19.             if(window.XMLHttpRequest)
  20.               {
  21.                xmlhttp = new XMLHttpRequest;
  22.               }
  23.             else
  24.               {
  25.                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  26.               }
  27.             xmlhttp.onreadystatechange=function()
  28.              {
  29.  
  30.                if(xmlhttp.readyState==4 && xmlhttp.status==200)
  31.  
  32.                 {
  33.                 document.getElementById("preguntaselect").innerHTML=xmlhttp.responseText;
  34.                  }
  35.              }        
  36.  
  37.             xmlhttp.open("GET","db.php?c="+str,true);
  38.  
  39.             xmlhttp.send()
  40.  
  41.           }
  42.  
  43.        
  44.        
  45.  
  46.         function segundoslect(str){
  47.  
  48.             var xmlhttp;
  49.  
  50.             if(str=="")
  51.  
  52.               {
  53.  
  54.                document.getElementById("txtHint").innerHTML="";
  55.  
  56.                return;
  57.  
  58.               }
  59.  
  60.             if(window.XMLHttpRequest)
  61.  
  62.               {
  63.  
  64.                xmlhttp = new XMLHttpRequest;
  65.  
  66.               }
  67.  
  68.             else
  69.  
  70.               {
  71.  
  72.                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  73.  
  74.               }
  75.  
  76.             xmlhttp.onreadystatechange=function()
  77.  
  78.               {
  79.  
  80.                if(xmlhttp.readyState==4 && xmlhttp.status==200)
  81.  
  82.                 {
  83.  
  84.                  document.getElementById("pruebas").innerHTML=xmlhttp.responseText;
  85.  
  86.                  }
  87.  
  88.               }        
  89.  
  90.             xmlhttp.open("GET","NuevaEvaluacion.php?p="+str,true);
  91.  
  92.             xmlhttp.send()
  93.  
  94.         }
  95.  
  96.     </script>
  97.  
  98.  
  99.  
  100. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  101.  
  102. <title>Documento sin título</title>
  103.  
  104. <style type="text/css">
  105.  
  106. body,td,th {
  107.  
  108.     font-family: Tahoma, Geneva, sans-serif;
  109.  
  110.     color: #000;
  111.  
  112. }
  113.  
  114. #form1 table {
  115.  
  116.     font-size: 16px;
  117.  
  118. }
  119.  
  120. #form1 table tr td h4 strong {
  121.  
  122.     color: #FFF;
  123.  
  124. }
  125.  
  126. body,td,th {
  127.  
  128.     font-family: Verdana, Geneva, sans-serif;
  129.  
  130. }
  131.  
  132. #textfield{
  133.  
  134.    
  135.  
  136.     height: 22px;
  137.  
  138.     background: #cfcdcd;
  139.  
  140.     border: solid medium #3f3f3f;
  141.  
  142.     margin: -2px 0 0 0;
  143.  
  144.     border-radius:4px;
  145.  
  146.     padding:0 5px;
  147.  
  148. }
  149.  
  150. #button{
  151.  
  152.     font-weight: bold;
  153.  
  154.     width: 245px;
  155.  
  156.     cursor: pointer;
  157.  
  158.     padding: 8px;
  159.  
  160.     margin: 0px 0px 0px 0px;
  161.  
  162.     border: 1px solid #ccc;
  163.  
  164.     background: #dadee3;
  165.  
  166.     border-radius: 5px 5px 5px 5px;
  167.  
  168. }
  169.  
  170. #button:hover {
  171.  
  172.     background: #d4e7ff;
  173.  
  174. }
  175.  
  176. #form1 table tr td h5 strong {
  177.  
  178.     color: #FFF;
  179.  
  180. }
  181.  
  182. #form1 table tr td strong {
  183.  
  184.     color: #FFF;
  185.  
  186. }
  187.  
  188. #form1 table {
  189.  
  190.     font-size: 14px;
  191.  
  192. }
  193.  
  194.  
  195. </head>
  196.  
  197.  
  198.  
  199. <?php
  200.  
  201. include_once "conexion.php";
  202.  
  203.  
  204. $p=$_GET['p'];
  205.  
  206.  
  207. $miselect= 'SELECT Codigo, Nombre FROM Cuestionarios';
  208.  
  209. $resul= mysql_query($miselect);
  210.  
  211.  
  212.  
  213. $sqlpreg= "SELECT * FROM Respuestas WHERE CodPregunta = '$p'";
  214.  
  215. $respreg= mysql_query($sqlpreg);
  216.  
  217.  
  218. ?>
  219.  
  220.  
  221. <form id="form1" name="form1" method="post" action="">
  222.  
  223.  
  224. <table width="698" height="373" border="0" align="center">
  225.  
  226.   <tr>
  227.  
  228.     <td height="21" colspan="6" align="right"><button type="button" id="button" onclick="location.href = 'Administracion.php'" >Atras</button></td>
  229.  
  230.   </tr>
  231.  
  232.  
  233.  
  234.   <tr>
  235.  
  236.     <td height="21" colspan="6" id="pruebas">
  237.  
  238.  
  239.     </td>
  240.  
  241.   </tr>
  242.  
  243.   <tr>
  244.  
  245.     <td height="24" align="right"> Evaluación: </td>
  246.  
  247.     <td colspan="4"><label for="select"></label>
  248.  
  249.       <select name="selecteval" id="select" onchange="showselect(this.value)">
  250.  
  251.             <?php
  252.  
  253.                while($row = mysql_fetch_array($resul)) {
  254.  
  255.                $CodEval = $row["Codigo"];
  256.  
  257.                $nombre = $row["Nombre"];
  258.  
  259.                echo "<option value=".$CodEval.">".$nombre."</option>";
  260.  
  261.                 }
  262.  
  263.              ?>
  264.  
  265.        </select>
  266.  
  267. </td>
  268.  
  269.   </tr>
  270.  
  271.   <tr>
  272.  
  273.     <td width="115" height="24" align="right">Nueva Pregunta</td>
  274.  
  275.     <td colspan="4"><textarea name="nuevapregunta" cols="35" id="textfield2"></textarea></td>
  276.  
  277.   </tr>
  278.  
  279.   <tr>
  280.  
  281.     <td height="27" align="right"> Preguntas: </td>
  282.  
  283.     <td colspan="2" id="preguntaselect">
  284.  
  285.  
  286.  
  287.     </td>
  288.  
  289.     <td colspan="2"><input type="submit" name="button2" id="button" value="Agregar" />
  290.  
  291.     </td>
  292.  
  293.   </tr>
  294.  
  295.   <tr>
  296.  
  297.     <td height="29" colspan="5" align="right" bgcolor="#FFFFFF">&nbsp;</td>
  298.  
  299.     </tr>
  300.  
  301.   <tr>
  302.  
  303.     <td height="30" align="right" bgcolor="#EAEAEA">Respuesta: </td>
  304.  
  305.     <td colspan="4" bgcolor="#EAEAEA"><input name="textfield2"  type="text" id="textfield" size="80" /></td>
  306.  
  307.     </tr>
  308.  
  309.   <tr>
  310.  
  311.     <td height="34" align="right" bgcolor="#EAEAEA">&nbsp;</td>
  312.  
  313.     <td colspan="2" bgcolor="#EAEAEA"><input type="checkbox" name="checkbox" id="checkbox" />
  314.  
  315.       Respuesta Correcta. </td>
  316.  
  317.     <td colspan="2" align="left" bgcolor="#EAEAEA"><input type="submit" name="button" id="button" value="Agregar respuesta a esta pregunta" /></td>
  318.  
  319.  
  320.   </tr>
  321.   <tr>
  322.  
  323.     <td  colspan="5" align="right">&nbsp;</td>
  324.     </tr>
  325.  
  326.   <tr>
  327.  
  328.     <td height="29" align="center" bgcolor="#333333"><strong>Opciones</strong></td>
  329.  
  330.     <td width="231" align="center" bgcolor="#333333"><strong>Respuestas</strong></td>
  331.  
  332.     <td width="80" align="center" bgcolor="#333333"><strong>Editar</strong></td>
  333.  
  334.     <td width="146" align="center" bgcolor="#333333"><strong>Borrar</strong></td>
  335.  
  336.     <td width="104" align="center" bgcolor="#333333"><strong>Flag</strong></td>
  337.  
  338.    
  339.  
  340.   </tr>
  341.  
  342.             <?php
  343.  
  344.                while($row1 = mysql_fetch_array($respreg)) {
  345.  
  346.                $resptas = $row1["Respuesta"];
  347.  
  348.         ?>
  349.  
  350.   <tr>
  351.  
  352.     <td height="24" align="center">1</td>
  353.  
  354.     <td align="center"><?php echo $resptas; }   ?></td>
  355.  
  356.  
  357.     <td align="center">&nbsp;</td>
  358.  
  359.    
  360.   </tr>
  361.  
  362. </form>
  363. </body>
  364. </html>

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