Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/03/2007, 05:56
ciberpata
 
Fecha de Ingreso: junio-2003
Ubicación: Santiago de Compostela
Mensajes: 603
Antigüedad: 21 años, 7 meses
Puntos: 0
Selects dependientes para ASP-ACCESS Ej. de Tunait.com

Un saludo:
Estoy intentando hacer funcionar el codigo de ejemplo de Tunait que aparece en www.tunait.com para Selects dependientes con ACCESS y ASP, ya que funciona tanto firefox como iexplorer.

El caso es que el primer select muestra las categorías y el segundo select solo muestra la categoria seleccionada en el primer select.

En mi caso solo me interesa con dos selectores. Alguien puede decirme si solo sería necesario eliminar el tercer selector del codigo html?.

No consigo dar con lo que estoy haciendo mal. Podría alguien echarme una mano.
Gracias por todo

Los valores que uso en las tablas son:
Diseño:

categoria_productos
---------------------
id_categoria: Autonumerico
nombre_categoria: Texto(50)
id_categoria_padre: Numero (Entero Largo)

productos:
-----------
id_producto: Autonumerico
nombre_producto: Texto(50)
id_categoria: (Entero Largo)


Valores Categoria:
id_categoria Nombre_categoria id_categoria_padre
---------------------------------------------------------
1 Cementos 0
2 Herramientas 0
3 Pulidores 0

Valores Producto

id_producto Nombre_producto id_categoria
-----------------------------------------------------
1 Blanco 1
2 Transparente 1
3 Metalicas 2
4 Plasticas 2
5 Manuales 3
6 Automáticos 3


El codigo del fichero html, es el siguiente:
Código:
<!DOCTYPE html 
      PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es">
<head>
<title>Listas dependientes con PHP y mySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">



/************************************************
 Listas dependientes por Tunait!(5/1/04)
 Si quieres usar este script en tu sitio eres libre de hacerlo con la condición
 de que permanezcan intactas estas líneas, osea, los créditos.
 No autorizo a publicar y ofrecer el código en sitios de script sin previa autorización
 Si quieres publicarlo, por favor, contacta conmigo.
 http://javascript.tunait.com/
 [email protected]
*************************************************/
<!--
function slctr(texto,valor){
   this.texto = texto
   this.valor = valor
}
function slctryole(cual,donde){
   if(cual.selectedIndex != 0){
      donde.length=0
      cual = eval(cual.value)
      for(m=0;m<cual.length;m++){
         var nuevaOpcion = new Option(cual[m].texto);
         donde.options[m] = nuevaOpcion;
         if(cual[m].valor != null){
            donde.options[m].value = cual[m].valor
         }
         else{
            donde.options[m].value = cual[m].texto
         }
      }
   }
}

<%set Conec= Server.CreateObject("ADODB.Connection")    
Set Rc=Server.CreateObject("ADODB.Recordset")
Conec.ConnectionString = "prueba.com"
query = "select * from categorias_productos order by id_categoria_padre"
conec.open
set rc = conec.execute(query)
do while not rc.eof 
contador = 0
%>
var cat_<%=rc("id_categoria") %>=new Array()
    cat_<%=rc("id_categoria") & "[" & contador %>] = new slctr('- -<%= rc("nombre_categoria") %>- -')
<% 
    if rc("id_categoria_padre") = 0 then
       sufijo = "categoria"
       query2 ="select * from categorias_productos  where id_categoria_padre = " & rc("id_categoria") & " order by nombre_" & sufijo
    else
       sufijo = "producto"
       query2 = "select * from productos where id_categoria = " & rc("id_categoria") & " order by nombre_" & sufijo
    end if 
    set rc2 = conec.execute(query2)
    do while not rc2.eof 
    contador = contador + 1
    %>
    cat_<%= rc("id_categoria") & "[" & contador %>] = new slctr("<%=rc2("nombre_" & sufijo)%>",'cat_<%=rc2("id_categoria")%>')
<% 
   rc2.moveNext
    Loop
rc.moveNext
Loop
set rc = nothing
set rc2 = nothing
%>
//-->
</script>
</head>
<body>
<form action="../accion">
    <fieldset>
    <select name="select" onchange="slctryole(this,this.form.select2)">
      <option>- - Seleccionar - -</option>
      <%
    query = "select * from categorias_productos where id_categoria_padre = 0 order by nombre_categoria" 
    set rc = conec.execute(query)
    do while not rc.eof %>
      <option value="cat_<%=rc("id_categoria")%>"><%=rc("nombre_categoria")%></option>
      <%
    rc.moveNext
    Loop
    conec.close
    set conec = nothing
%>
    </select>
    <select name="select2" onchange="slctryole(this,this.form.select3)">
        <option>- - - - - -</option>
    </select>
    <select name="select3">
        <option>- - - - - -</option>
    </select>
  </fieldset>
</form>
</body>
</html>
__________________

Espero haber aprendido algo de tí.
A mi padre.