Newbie: Help with Combobox population

Hi everyone, I'm a newbie and this is my first message, so bear with me if I make any mistake.

I want to do the following:

In a part of an Intranet, I'd like to have a combobox which lists Categories of works. Then, depending on the Category selected, I'd like another combobox, to populate with all the files of a folder corresponding to the category selected.

I've done a few comboboxes that read the contents of directories, but none, depending on a previous selection.

The database is set (in Access), and divided in 2 tables:
tblTipocat -> idCat nomCat dirCat
tblDescripciones -> idDescr idCat descripcioneng imagen

and then I have a Consult table with the following:
cnsDescripciones -> idDescr idCat descripcioneng imagen dirCat

The Code I have so far is this:

<%
var error="";
var reg=new registro();
reg.addCampo("idCat","COMBO");
reg.addCampo("descripcioneng","TEXTAREA");
reg.addCampo("imagen","COMBOFILES");
reg.addCampo("idDescr","HIDDEN");
reg.addCampo("dirCat","HIDDEN");
reg.idCat.requerido=true;
reg.descripcioneng.requerido=true;
reg.descripcioneng.opciones="cols=50 rows=5 wrap=VIRTUAL";

var cn=Server.CreateObject("ADODB.Connection");
cn.Open(MM_admin_STRING);
var rs= Server.CreateObject("ADODB.recordset");
reg.idCat.rs=cn.Execute("SELECT * FROM tblTipocat;");
reg.dirCat.rs=cn.Execute("SELECT dirCat FROM tblTipoCat WHERE dirCat="+datoDB(reg.idCat.valor)+";";
var ruta="\\intranet\\users\\website\\portfolio\\"+datoDB(reg.dirCat.valor)+";";
ruta=Server.MapPath(ruta);
Session("ruta")=ruta;

if(d2str(Request("eliminar"))!=""){
var SQL="DELETE FROM tblDescripciones WHERE idDescr="+Request("eliminar")+";";
rs = cn.Execute(SQL);
}

if(Request("guardar")=="Save"){
reg.request();
if(!reg.error){
if(reg.idDescr.valor!=""){
SQL="UPDATE tblDescripciones "
SQL+="SET idCat ="+ reg.idCat.valor
SQL+=" , descripcioneng ="+ datoDB(reg.descripcioneng.valor);
SQL+=" , imagen ="+ datoDB(reg.imagen.valor);
SQL+=" , dirCat ="+ datoDB(reg.dirCat.valor);
SQL+=" WHERE idDescr ="+ reg.idDescr.valor;
//Response.Write(SQL)
cn.Execute(SQL);
Response.Redirect(estaUrl)
} else {
SQL="INSERT INTO tblDescripciones (idCat,descripcioneng,imagen,dirCat) "
SQL+="VALUES ("+ reg.idCat.valor+","+ datoDB(reg.descripcioneng.valor)+","+ datoDB(reg.imagen.valor)+","+ datoDB(reg.dirCat.valor)+");";//
cn.Execute(SQL);
Response.Redirect(estaUrl)
}
}
}
%>

and on an .inc file I have registered prototypes:

<%//@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<%
//Clase Registro de Campos
function registro(){
this.contenido=new Array();
this.cant=0;
this.metodo=Request;
this.error;
this.readOnly=false;
this.medida="120";
this.estilo="campo"
}

registro.prototype.addCampo = function (sName, vValue) {
this[sName] = new campo(sName,vValue);
this[sName].estilo=this.estilo;
this[sName].medida=this.medida;
this[sName].valor=""
this.contenido[this.cant]=this[sName];
this.cant++;
}

registro.prototype.request = function () {
var i=this.cant;
for(;i>0;i--){
this.contenido[i-1].request(this.metodo);
if(this.contenido[i-1].error==true) {
this.error=true;
}
}
}

registro.prototype.clear = function () {
var i=this.cant;
for(;i>0;i--){
this.contenido[i-1].valor="";
}
}

///Clase campo
function campo(nom,tip){
var nombre;
var tipo;
var valor;
var medida;
var opciones;
var estilo;
var rs;
this.requerido=false;
this.error=false;
this.strError="Required"
//Iniciales
if(nom) this.nombre=nom;
if(tip) this.tipo=tip;
}

campo.prototype.request=function (metodo){
if(!metodo) metodo=Request;
var val=String(metodo(this.nombre));
if(val=="undefined") val="";
this.valor=val;
if(this.requerido==true && val=="") this.error=true;
return val;

}

campo.prototype.toString=function (){
if(this.nombre!="") {
if(this.tipo=="TEXT" || this.tipo=="PASSWORD" || this.tipo=="HIDDEN"){
str="<input name=\""+this.nombre+"\" type=\""+this.tipo+"\" value=\""+this.valor+"\" ";
str+="style=\"width:"+this.medida+"px;\" ";
str+="class=\""+this.estilo+"\" ";
str+=this.opciones+"> ";
if(this.requerido && this.tipo!="HIDDEN"){
if(this.error) str+=this.strError; else str+="*";
}
Response.Write(str);
}
if(this.tipo=="TEXTAREA"){
str="<textarea name=\""+this.nombre+"\" value=\""+this.valor+"\" ";
str+="class=\""+this.estilo+"\" ";
str+=this.opciones+"></textarea> ";
if(this.requerido && this.tipo!="HIDDEN"){
if(this.error) str+=this.strError; else str+="*";
}
Response.Write(str);
}
if(this.tipo=="COMBO"){
Response.Write("<select name=\""+this.rs.Fields(0).Name+"\" class=\""+this.estilo+"\">");
for(;!this.rs.EOF;this.rs.MoveNext()) {
var selected= (this.rs.Fields(0) == this.valor)? "SELECTED" : "";
Response.Write("<option value=\""+this.rs.Fields(0)+"\" "+selected+" >"+this.rs.Fields(1)+"</option>");
}
Response.Write("</select>")//*/
}
if(this.tipo=="COMBOFILES"){
var fso=Server.CreateObject("Scripting.FileSystemObject");
ruta=d2str(Session("ruta"));
if(fso.FolderExists(ruta)==true) {
var mf, f;
mf = fso.GetFolder(ruta);
f = new Enumerator(mf.Files);
Response.Write("<select name=\""+this.nombre+"\" class=\""+this.estilo+"\">");
for (; !f.atEnd(); f.moveNext()){
var selected= (f.item().name == this.valor)? "SELECTED" : "";
Response.Write("<option value=\""+f.item().name+"\" "+selected+">"+f.item().name+"</option>");
}
Response.Write("</select>")//*/
}
}
}
}

%>

The thing is that I don't know how to make the second combobox to load directory's contents based on the selection of the first one.

Can anyone give me a hand with this?

Thanks in advance.
[6641 byte] By [lordvader] at [2007-11-19 20:09:41]
# 1 Re: Newbie: Help with Combobox population
Here are two examples of dependent dropdowns
Pure ASP
http://computer-helpforum.com/asp/aspfree/dependent_dropdown/ASP_dependent_dropdown_2.asp
http://computer-helpforum.com/asp/aspfree/dependent_dropdown/dependent_dropdown.zip

http://forums.aspfree.com/code-bank-54/dynamic-dependant-listboxes-53159.html
degsy at 2007-11-8 0:22:46 >