Ver Mensaje Individual
  #3 (permalink)  
Antiguo 14/07/2015, 06:08
riz08
 
Fecha de Ingreso: julio-2015
Ubicación: ANYWHERE
Mensajes: 3
Antigüedad: 8 años, 10 meses
Puntos: 0
Respuesta: Como seleccionar ele elemento abuelo o bisabuelo apartir del atributo val

En primer lugar gracias por responder!.

Aqui tienes la partes de codigo javascript y HTML :

<html>
<head>
Código Javascript:
Ver original
  1. <script src="jquery-2.1.3.min.js" type="text/javascript"></script>
  2. <script type="text/javascript">
  3. function buscar_enArray(dato,array){
  4.  
  5. var i=0;
  6. while(i<array.length){
  7.    
  8.     if(array[i]== dato){
  9.        
  10.         return true;
  11.         break;
  12.        
  13.         }
  14.         else{return false;}
  15.        
  16.        
  17.     i++;
  18.    
  19.     }
  20. }
  21.  
  22.  
  23. $(document).ready(function(e) {
  24.    
  25.  
  26.  $("#seleccio_org").on("change",function(){
  27. //Creacion array campo  Organization
  28.         llista=document.formulari.elements["seleccio_org[]"];
  29.         llista2=document.formulari.elements["seleccio_org[]"].selectedIndex;
  30.         opcions = llista.options;
  31.         var dades_ORG=[];  
  32.         if( llista2 !=-1 ) {
  33.          for (i=0;i<opcions.length;i++) {
  34.               if (opcions[i].selected==true) {
  35.                   dades_ORG.push(opcions[i].value);
  36.                         }
  37.                      }
  38.                   }
  39.         else{
  40.             for (i=0;i<opcions.length;i++){
  41.             dades_ORG.push(opcions[i].value);
  42.         }
  43.     }  
  44.  
  45. //Creacio array Llista CHECKBOX      
  46.     var dades_llista= [];
  47.     //$( "input[ name='org[]']:not(:checked)").each(function(){
  48.     //$("input[name='org[]']:checked").each(function(){
  49.        
  50.     $("input[name='org[]'").each(function(index, element) {
  51.  
  52.     dades_llista.push($(this).val());
  53.  
  54.     });
  55.        
  56.    
  57. for(var j=0;j<dades_llista.length;j++){
  58. //alert("valors de llista: "+dades_llista[j]+" valors de ORG: "+dades_ORG[x]);
  59.      if(buscar_enArray(dades_llista[j],dades_ORG)){
  60.    
  61.             /*$("input[value="+dades_ORG[j]+"]").siblings('label').parent('li').parent('div').hide(300);
  62.             $("input[value="+dades_ORG[j]+"]").css("cheked","false");
  63.             $("#ol_eval").find('div').hide(300);*/
  64.            
  65.             $("#CAPA_ORG_"+j).show(300);
  66.             $("#CAPA_EVAL_"+j).show(300);
  67.             $("#org_"+j).css("checked",true);
  68.           }
  69.          
  70.           else{
  71.      
  72.             //alert("dades_llista: "+dades_llista);
  73.             /*$("input[value="+dades_ORG[j]+"]").siblings('label').parent('li').parent('div').show(300);
  74.             $("input[value="+dades_ORG[j]+"]").css("cheked","true");
  75.             $("#ol_eval").find('div').show(300);*/
  76.            
  77.             ("#CAPA_ORG_"+j).hide(300);
  78.             $("#CAPA_EVAL_"+j).hide(300);
  79.             $("#org_"+j).css("checked",false);
  80.              
  81.               }
  82.          }
  83.  
  84.      }); //al seleccionar camp ORG
  85. });//document
  86. </script>
</head>
<body>


Código PHP:
Ver original
  1. <?php
  2.  
  3.  
  4. include('conectar.php');
  5.  
  6.  if (!$conexio=conectar_bd()){
  7.    
  8.     echo"Imposible conectarse con la base de datos: ".mysqli_connect_error();
  9.    
  10.     }
  11.  
  12. echo"<td align='center'><b>Organization</b><br><select id='seleccio_org' name='seleccio_org[]'  style='width:120px' multiple size='5' onChange='obtenir_test();popp()' >"; 
  13.        echo" <option value='0'> --Escoja opci&oacute;n-- </option>";    
  14.  
  15.     $org = mysqli_query($conexio, "SELECT * from organization");   
  16.     while($fila=mysqli_fetch_assoc($org)){
  17.     echo"<option value='".$fila['organization']."' id='$idopt".$id."' selected/>"."<b>".$fila['organization']."</b>"."</option>";
  18.      $id++;
  19.        }   
  20.  
  21. ?>  
  22.  
  23.  
  24. <ol class="tree">
  25.         <li><label for="organization"><b>Organization</b></label> <input type="checkbox"   id="organization" value="organization" " onclick="visualitzarLLista()"/>
  26.             <ol>  
  27.              
  28.                  
  29.                          
  30.                     <div id="GENERAL" style="display: none;"></div>
  31.          
  32.          
  33.                
  34.                  
  35.             </ol>
  36.        </li>
  37.                      
  38. </ol>  
  39. </body>
  40. </html>
  41.  
  42. La capa "GENERAL" se carga con los datos mediante ajax que llama al archivo show.php  al cargar la pagina.Este archivo obtiene los datos enviados desde ajax.y los lista mediante como un arbol , las capas dinamicas las genero de esta forma dentro del archivo show.php:
  43.  
  44.  
  45. <?php
  46.  
  47. $iden="org_";
  48. $capaEVAL="CAPA_EVAL_";
  49. $capaORG="CAPA_ORG_";
  50. $idorg=0;
  51. $numcapa=0;
  52. $numORG=0;
  53.  
  54.  
  55. for($i=0;$i<count($valor1);$i++){  
  56. echo"<div id='$capaORG".$numORG."' style='display: block;' class='abuelo'";                
  57. echo"<li><label for='organization'>".$valor1."</label><input type='checkbox' id='$iden".$idorg."' name='org[]' value='".$valor1."' onclick='show_llista($seleccio_eval,$numcapa,$llista_eval,$pagina,$aa);visualitzarLLista($idorg,$numcapa)';>";//per mostrar evaluation
  58. echo"</div>";
  59.         echo"<ol id='ol_eval'>";
  60.         echo"<div id='$capaEVAL".$numcapa."' style='display: none;'>";  
  61.         echo"</div>";          
  62.         echo"</ol></li>";
  63.         $numcapa++;
  64.         $idorg++;  
  65.         $numORG++;
  66.      
  67.             }  
  68.          }
  69.        }
  70.     }
  71. }
  72.  
  73. ?>




Si hay cualquier aclaració que veais , solo me lo teneis que comentar.
Un saludo y gracias otra vez.

Última edición por riz08; 14/07/2015 a las 06:18