Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/03/2009, 12:44
Avatar de cesarpunk
cesarpunk
 
Fecha de Ingreso: enero-2008
Ubicación: Lima
Mensajes: 943
Antigüedad: 17 años, 1 mes
Puntos: 9
creando treeview

hola, disculpen si esto es el foro equivocado pero creo que intervienen mas php, aqui vamos:

Pretendo hacer un treeview de 2 niveles... primer nivel de categoria de productos y el segundo su subcategoria.

La categoria la genero de una busqueda de una bd, debajo esta sus subcategorias generadas tambien con una consulta pero la tabla que contiene esa subcategoria esta dentro de un div: <div id="<?php echo $idcategoria;?>" style="display:none;"> que tiene el id de su categoria a la que pertenece (generado con while) y que esta oculto con la intencion de presionar un boton y hacerlo aparecer y desaparecer simulando el treeview....

El problema es que esa accion lo hago con funciones js pero quisiera enganchar esa funcion con el $idcategoria:

function btnAbre() {
document.getElementById('iddiv').style.display='bl ock';
}

bueno intente poner un textbox oculto cuyo value sea tambien el $idcategoria y pasarlo al js y hacerlo asi:

function btnAbre() {
var codigo = document.formu.idtextbox.value;
document.getElementById(codigo).style.display='blo ck';
}

pero si ningun resultado, el error siempre me sale "esperando elemento", como podria capturar ese id para saber que div abrir? , espero me puedan dar una idea.... les dejo mi enorme codigo para que vean lo que intento hacer:

Código PHP:
<script type="text/JavaScript">
<!--
function btnAbre() {
var codigo = document.getElementById('idcat').value;
document.getElementById(codigo).style.display='block';
}

function btnCierra() {
var codigo = document.getElementById('idcat').value; 
document.getElementById(codigo).style.display='none';
}
//-->
</script>
<style type="text/css"> 
form {
margin:0px;
padding:0px;
}
</style>
<?php
require_once("includes/functions.php");
function 
modulo_Category(){
?>
<form name="frmcat" id="frmcat">
 <table width="200" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td height="24" colspan="3" align="center" valign="bottom" background="http://www.forosdelweb.com/images/trazos/emily_difusion_cabecera_iz.jpg" class="fuenteCabLateral"><strong>Categorias</strong></td>
            </tr>
          <tr>
            <td width="2" rowspan="3" bgcolor="#00892F"></td>
            <td>
            <?php
                
//LISTA DE CATEGORIAS
                
$sql="SELECT * FROM categoria where categoria_estado='1' order by categoria_nombre"
                
$res=mysql_query($sql); 
                
$num=mysql_num_rows($res);
                
//PREGUNTAMOS SI EXISTEN REGISTROS PARA GENERAR LA TABLA DE EMPRESAS HABILITADAS
                
if($num>0){
            
?>
            <table width="196" border="0" cellpadding="0" cellspacing="0">
                <tr>
                <td height="2"></td>
                </tr>
            <?php
            
//GENERANDO NUMERO, CAMPOS DE REGISTROS
                
while( $fila mysql_fetch_array$res ) ) {
               
//generamos los campos que van en las tablas
               
$idcategoria $fila["categoria_id"];
               
$nomcategoria $fila["categoria_nombre"];
            
?>
              <tr>
                <td width="5"></td>
                <td width="9">
                <?php
                $catnum 
return_subcategorias($idcategoria);
                if(
$catnum>0){
                    echo 
'<div id="abre'.$idcategoria.'"><img src="http://www.forosdelweb.com/images/treeItem1.gif" width="9" height="9" style="cursor:pointer;" onclick="javascript:btnAbre();" /></div>';
                    echo 
'<div id="cierra'.$idcategoria.'" style="display:none;"><img src="http://www.forosdelweb.com/images/treeItem2.gif" width="9" height="9" style="cursor:pointer;" onclick="javascript:btnCierra();" /></div>';
                    
                }
                else{
                    echo 
'<img src="http://www.forosdelweb.com/images/treeItem0.gif" width="9" height="9" />';
                }
                
?>
                </td>
                <td width="5"></td>
                <td height="15" align="left" class="fuenteMenuCategoria"><a href="<?php echo "categorias.php?catID=$idcategoria"?>" class="enlaceCategoria"><?php echo $nomcategoria?></a><input name="idcat" type="text" id="idcat" size="2" value="<?php echo $idcategoria?>" /></td>
              </tr>
              
              <tr>
              <td colspan="3"></td>
              <td>
              <div id="<?php echo $idcategoria;?>" style="display:none;">
              <?php 
              
//LISTA DE SUBCATEGORIAS
                
$sql2="SELECT * FROM subcategoria where subcategoria_estado='1' and categoria_id='$idcategoria'"
                
$res2=mysql_query($sql2); 
                  
$num2=mysql_num_rows($res2);
                if(
$num2>0){
              
?>
                  <table width="100%">
              <?php
                
//GENERANDO NUMERO, CAMPOS DE REGISTROS
                
while( $fila2 mysql_fetch_array$res2 ) ) {
                
//generamos los campos que van en las tablas
                
$idsubcategoria $fila2["subcategoria_id"];
                
$nomsubcategoria $fila2["subcategoria_nombre"];
              
?>
                      <tr>
                        <td width="5"></td>
                        <td width="9"><img src="http://www.forosdelweb.com/images/iconos/emily_difusion_vineta.jpg" width="9" height="7" /></td>
                        <td width="5"></td>
                        <td height="15" align="left" class="fuenteMenuCategoria"><a href="<?php echo "categorias.php?catID=$idsubcategoria"?>" class="enlaceCategoria"><?php echo $nomsubcategoria?></a></td>
                      </tr>
             <?php
                

             
?>
                  </table>
             <?php
            
//CERRAMOS EL IF DE LISTA DE SUBCATEGORIAS
            
}
            
?>
              </div></td></tr>
            <?php
                

            
?>
              <tr>
                <td height="2"></td>
                </tr>
            </table>
            <?php
            
//CERRAMOS EL IF DE LISTA DE CATEGORIAS
            
}
            else{
                echo 
" ";
            }
            
?>
            </td>
            <td width="2" rowspan="3" bgcolor="#00892F"></td>
          </tr>
          <tr>
            <td height="1" bgcolor="#00892F"></td>
            </tr>
          <tr>
            <td><table width="196" border="0" cellpadding="0" cellspacing="0">
              <tr>
                  <td height="5"></td>
              </tr> 
              <tr>
                <td width="5"></td>
                <td width="9"><img src="http://www.forosdelweb.com/images/iconos/emily_difusion_vineta.jpg" width="9" height="7" /></td>
                <td width="5"></td>
                <td align="left" class="fuenteMenuCategoria"><a href="categorias.php" class="enlaceCategoria">Todas las Categor&iacute;as </a></td>
              </tr>
            </table></td>
            </tr>
          <tr>
            <td colspan="3"><strong><img src="http://www.forosdelweb.com/images/trazos/emily_difusion_pie_iz.jpg" width="200" height="18" /></strong></td>
            </tr>
        </table>
</form>
<?php
}
?>
__________________
Quitenme la vida pero no la bebida.