Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/04/2013, 10:54
alexperaza
 
Fecha de Ingreso: diciembre-2012
Mensajes: 178
Antigüedad: 11 años, 4 meses
Puntos: 2
Pregunta listas dependientes segunda lista no captura valor

Hola como estan tengo un problemilla con la creacion de dos listas dependientes una de la otra.
La funcionalidad esta muy bien lo que no esta bien es que la segunda lista no me guarda el valor correspondiente en la base de datos ya que siempre se queda NULL me podrian decir en que estoy fallando? si me pueden ayudar. Muchas gracias

Codigo para la primer lista
Código PHP:
Ver original
  1. <div id="dep" style="width:200px; float:left">
  2.           <select name="id_categoria" id="id_categoria" onchange="llamarAjaxGETpro()"><option>Seleccione Categoria.</option>
  3.   <?php
  4.   while($row_ConsulCat=mysql_fetch_array($ConsulCat)){
  5.   echo'<option value="'.$row_ConsulCat['id_categoria'].'">'.$row_ConsulCat['nombre_categoria'].'</option>';
  6.   }
  7.  
  8.   ?></select> </div>

Codigo para la segunda
Código PHP:
Ver original
  1. <?php
  2.  require_once('Connections/clasi.php');
  3. $valor=$_GET['valor'];
  4. mysql_select_db($database_clasi, $clasi);
  5. $query_ConsulCat = "SELECT * FROM categorias WHERE categorias.IdPadre='$valor' ORDER BY categorias.nombre_categoria";
  6. $ConsulCat = mysql_query($query_ConsulCat, $clasi) or die(mysql_error());
  7. $row_ConsulCat = mysql_fetch_assoc($ConsulCat);
  8. $totalRows_ConsulCat = mysql_num_rows($ConsulCat);
  9. echo'<select id="IdPadre" >';
  10. echo'<option >seleccione provincia</option>';
  11. while($row_ConsulCat=mysql_fetch_array($ConsulCat)){
  12.   echo'<option value="'.$row_ConsulCat['IdPadre'].'">'.$row_ConsulCat['nombre_categoria'].'</option>';
  13.   }
  14.  
  15. echo'</select>';
  16. ?>

este ultimo esta en un archivo llamado provincia.php

Luego esta el codigo de ajax para asignar el valor a la segunda lista

Código Javascript:
Ver original
  1. <script>
  2. //hacer que funcione con diferentes navegadores
  3. function requerir(){
  4.     try{
  5.     req=new XMLHttpRequest();
  6.     }catch(err1){
  7.         try{
  8.         req=new ActiveXObject("Microsoft.XMLHTTP");
  9.         }catch(err2){
  10.             try{
  11.             req=new ActiveXObject("Msxml2.XMLHTTP");
  12.             }catch(err3){
  13.             req= false;
  14.             }
  15.         }
  16.     }
  17. return req;
  18. }
  19.  
  20.  
  21. var peticion=requerir();
  22.  
  23. function llamarAjaxGETpro(){
  24. var aleatorio=parseInt(Math.random()*999999999);
  25. valor=document.getElementById("id_categoria").value;
  26. var url="provincia.php?valor="+valor+"&r="+aleatorio;
  27. peticion.open("GET",url,true);
  28. peticion.onreadystatechange =respuestaAjaxpro;
  29. peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  30. peticion.send(null);
  31. }
  32.  
  33. function llamarAjaxGETdis(){
  34. var aleatorio=parseInt(Math.random()*999999999);
  35. valor=document.getElementById("IdPadre").value;
  36. var url="distrito.php?valor="+valor+"&r="+aleatorio;
  37. peticion.open("GET",url,true);
  38. peticion.onreadystatechange =respuestaAjaxdis;
  39. peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  40. peticion.send(null);
  41. }
  42.  
  43. function respuestaAjaxpro(){
  44.  
  45.     if(peticion.readyState==4){
  46.         if(peticion.status==200){
  47.         //alert(peticion.responseText);
  48.         document.getElementById("pro").innerHTML=peticion.responseText;
  49.         }else{
  50.         alert("ha ocurrido un error"+peticion.statusText);
  51.         }
  52.     }
  53. }
  54. function respuestaAjaxdis(){
  55.  
  56.     if(peticion.readyState==4){
  57.         if(peticion.status==200){
  58.         //alert(peticion.responseText);
  59.         document.getElementById("dis").innerHTML=peticion.responseText;
  60.         }else{
  61.         alert("ha ocurrido un error"+peticion.statusText);
  62.         }
  63.     }
  64. }
  65.  
  66. </script>


y por ultimo el HTML DE LAS LISTAS
Código HTML:
Ver original
  1. div id="pro" style="width:200px; float:left">
  2. <select name="IdPadre"  disabled="disabled" id="IdPadre">
  3. <option>seleccione Subcategoria</option>
  4. </div>


AYUDA ESTOY DESESPERADDO