Ver Mensaje Individual
  #3 (permalink)  
Antiguo 26/03/2012, 07:09
Avatar de jesusbg
jesusbg
 
Fecha de Ingreso: septiembre-2011
Ubicación: Santiago de Compostela
Mensajes: 41
Antigüedad: 13 años, 6 meses
Puntos: 1
Respuesta: Cambio de valor

Ok
El código controla los cambios en 5 selects que están relacionados. Cuando se cambia la categoría general se guarda el índice de la categoría seleccionada en $_SESSION["Ci"]. Al cambiar el siguiente select $_SESSION["Ci"] vale sizeof($_SESSION["categorias"])
pego el código:
Código PHP:
Ver original
  1. function modificarSlcsCatPrd(i) {
  2.     var slcCategorias=document.getElementById("slcCategoriasPrd");
  3.     var slcSubCat1=document.getElementById("slcSubCat1Prd");
  4.     var slcSubCat2=document.getElementById("slcSubCat2Prd");
  5.     var slcSubCat3=document.getElementById("slcSubCat3Prd");
  6.     var slcSubCat4=document.getElementById("slcSubCat4Prd");
  7.     if(i==1) {
  8.         slcSubCat1.length=1;
  9.         slcSubCat2.length=1;
  10.         slcSubCat3.length=1;
  11.         slcSubCat4.length=1;
  12.         <?php
  13.         $id_cat=0;
  14.         $i=0;
  15.         while(isset($_SESSION["categorias"][$i])) { ?>
  16.             if(slcCategorias.value==<?=$_SESSION["categorias"][$i]->get_id_categoria();?>) {
  17.                 <?php
  18.                 $_SESSION["Ci"]=$i;
  19.                 ?>
  20.                 alert("Prod i: " + <?=$i?>);
  21.                 alert("Prod S[i]: " + <?=$_SESSION["Ci"]?>);
  22.                 <?php
  23.                 if($_SESSION["categorias"][$i] instanceof Categoria) $sc1=$_SESSION["categorias"][$i]->get_subcategorias();
  24.                 $j=0;
  25.                 while(isset($sc1[$j])) { ?>
  26.                     var nuevoOpt = document.createElement('option');
  27.                     nuevoOpt.text = "<?=$sc1[$j]->get_nombre(); ?>"
  28.                     nuevoOpt.value = "<?=$sc1[$j]->get_id_categoria(); ?>"
  29.                     try {
  30.                         slcSubCat1.add(nuevoOpt, null); //todos navegadores
  31.                     }
  32.                     catch(ex) {
  33.                         slcSubCat1.add(nuevoOpt); // IE
  34.                     }
  35.                 <?php
  36.                     $j++;
  37.                 } ?>
  38.             }
  39.         <?php
  40.             $i++;
  41.         } ?>
  42.     }
  43.     else if(i==2) {
  44.         slcSubCat2.length=1;
  45.         slcSubCat3.length=1;
  46.         slcSubCat4.length=1;
  47.         alert("sc: " + slcSubCat1.value);
  48.         alert("$_SESSION['Ci']: " + <?=$_SESSION["Ci"]?>);
  49.         <?php
  50.         if(isset($_SESSION["Ci"])) {
  51.             if($_SESSION["categorias"][$_SESSION["Ci"]] instanceof Categoria) {
  52.                 //$sc1=$_SESSION["categorias"][$_SESSION["Ci"]]->get_subcategorias();
  53.                 $sc1=$_SESSION["categorias"][$id_cat]->get_subcategorias();
  54.             }
  55.             $i=0;
  56.            
  57.             while(isset($sc1[$i])) {?>
  58.                 alert("recorriendo: <?=$sc1[$i]->get_id_categoria()?>");
  59.                 if(slcSubCat1.value==<?=$sc1[$i]->get_id_categoria()?>) {
  60.                     alert("dentro del if");
  61.                     <?php
  62.                     $_SESSION["SC1i"]=$i;
  63.                     if($sc1[$i] instanceof Categoria)$sc2=$sc1[$i]->get_subcategorias();
  64.                     $j=0;
  65.                     while(isset($sc2[$j])) {?>
  66.                         var nuevoOpt = document.createElement('option');
  67.                         nuevoOpt.text = "<?=$sc2[$j]->get_nombre(); ?>"
  68.                         nuevoOpt.value = "<?=$sc2[$j]->get_id_categoria(); ?>"
  69.                         try {
  70.                             slcSubCat2.add(nuevoOpt, null); //todos navegadores
  71.                         }
  72.                         catch(ex) {
  73.                             slcSubCat2.add(nuevoOpt); // IE
  74.                         }
  75.                     <?php
  76.                         $j++;
  77.                     }?>
  78.                 }
  79.             <?php
  80.                 $i++;
  81.             }
  82.         }?>
  83.     }
  84.     else if(i==3) {
  85.         slcSubCat3.length=1;
  86.         slcSubCat4.length=1;
  87.         <?php
  88.         if(isset($_SESSION["Ci"]) && isset($_SESSION["SC1i"])) {
  89.             if($_SESSION["categorias"][$_SESSION["Ci"]] instanceof Categoria) $sc1=$_SESSION["categorias"][$_SESSION["Ci"]]->get_subcategorias();
  90.             if($sc1[$_SESSION["SC1i"]] instanceof Categoria) $sc2=$sc1[$_SESSION["SC1i"]]->get_subcategorias();
  91.  
  92.             $i=0;
  93.             while(isset($sc2[$i])) { ?>
  94.                 if(slcSubCat2.value==<?=$sc2[$i]->get_id_categoria()?>) {
  95.                     <?php
  96.                     $_SESSION["SC2i"]=$i;
  97.                     $sc3=$sc2[$i]->get_subcategorias();
  98.                     $j=0;
  99.                     while(isset($sc3[$j])) {?>
  100.                         var nuevoOpt = document.createElement('option');
  101.                         nuevoOpt.text = "<?=$sc3[$j]->get_nombre(); ?>"
  102.                         nuevoOpt.value = "<?=$sc3[$j]->get_id_categoria(); ?>"
  103.                         try {
  104.                             slcSubCat3.add(nuevoOpt, null); //todos navegadores
  105.                         }
  106.                         catch(ex) {
  107.                             slcSubCat3.add(nuevoOpt); // IE
  108.                         }
  109.                     <?php
  110.                         $j++;
  111.                     }?>
  112.                 }
  113.             <?php
  114.                 $i++;
  115.             }
  116.         }?>
  117.     }
  118.     else if(i==4) {
  119.         slcSubCat4.length=1;
  120.         <?php
  121.         if(isset($_SESSION["Ci"]) && isset($_SESSION["SC1i"]) && isset($_SESSION["SC2i"])) {
  122.             if($_SESSION["categorias"][$_SESSION["Ci"]] instanceof Categoria) $sc1=$_SESSION["categorias"][$_SESSION["Ci"]]->get_subcategorias();
  123.             if($sc1[$_SESSION["SC1i"]] instanceof Categoria) $sc2=$sc1[$_SESSION["SC1i"]]->get_subcategorias();
  124.             if($sc2[$_SESSION["SC2i"]] instanceof Categoria) $sc3=$sc2[$_SESSION["SC2i"]]->get_subcategorias();
  125.            
  126.             $i=0;
  127.             while(isset($sc3[$i])) {?>
  128.                 if(slcSubCat3.value==<?=$sc3[$i]->get_id_categoria()?>) {
  129.                     <?php
  130.                     $_SESSION["SC3i"]=$i;
  131.                     $sc4=$sc3[$i]->get_subcategorias();
  132.                     $j=0;
  133.                     while(isset($sc4[$j])) {?>
  134.                         var nuevoOpt = document.createElement('option');
  135.                         nuevoOpt.text = "<?=$sc4[$j]->get_nombre(); ?>"
  136.                         nuevoOpt.value = "<?=$sc4[$j]->get_id_categoria(); ?>"
  137.                         try {
  138.                             slcSubCat4.add(nuevoOpt, null); //todos navegadores
  139.                         }
  140.                         catch(ex) {
  141.                             slcSubCat4.add(nuevoOpt); // IE
  142.                         }
  143.                     <?php
  144.                         $j++;
  145.                     }?>
  146.                 }
  147.             <?php
  148.                 $i++;
  149.             }
  150.         }?>
  151.     }
  152.     else alert("Ha ocurrido un error desconocido: modificarSlcsCatPrd(i)");
  153. }

El problema no es al refrescar la página