Hi ther i have a function that creates a drop down based on the value of another drop down. These are named cat and subcat.
The arrays i use are generated by asp wich pulls the info from a sql db.
Everything works fine.
The script is used to categorize products in the DB.
My prolem occurs when i want to edit these records and not change the category.
I use asp to select the category by matching the item value against the one from the db.
I need to then populate the subCat drop down and select the appropriate subcat. The script to populate is normaly fired from the onChange event of the cat dropdown.
Is there any way i can simulate the onchange event for the cat drop down when the page loads?
or can someone suggest an alternative?
below is the code used to create the arrays
[CODE]
// create arrays on the fly from the DB
<%
Set oConn2 = Server.CreateObject(“ADODB.Connection”)
OConn2.ConnectionTimeout = 20
Set catSet = Server.CreateObject(“ADODB.RecordSet”)
Set getSubCat = Server.CreateObject(“ADODB.RecordSet”)
oConn2.Open connstring
sql = “SELECT Count(*) AS recTotal FROM cattypetbl”
set catSet = oConn.execute(sql)
recTotal = catSet(“recTotal”)
%>
var store = new Array();
<%
catCount = 1
do while catCount <= recTotal
%>
store[<% = (catCount) %>] = new Array(
<%
catSql = “select * from SubCatTypeTbl where CatTypeLink =” + cstr(catCount)
set getSubCat = oConn.execute(catSql)
do while not getSubCat.eof
%>
‘<% = getSubCat(“Descrip”) %>’,'<% = getSubCat(“SubCatTypeLink”) %>’
<% getSubCat.movenext
if not getSubCat.eof then response.write(“,”)
loop
%>);
<%
catCount = catCount + 1
loop
set getSubCat = nothing
%>
// create arrays on the fly from the DB
and here is the code to populate the drop downs
[CODE]
// scripts to populate drop downs
function init()
{
optionTest = true;
lgth = document.forms[0].subCat.options.length – 1;
document.forms[0].subCat.options[lgth] = null;
if (document.forms[0].subCat.options[lgth]) optionTest = false;
}
function populate()
{
if (!optionTest) return;
var box = document.forms[0].Cat;
var number = box.options[box.selectedIndex].value;
if (!number) return;
var list = store[number];
var box2 = document.forms[0].subCat;
box2.options.length = 0;
for(i=0;i<list.length;i+=2)
{
box2.options[i/2] = new Option(list[i],list[i+1]);
}
}
I have tried calling the populate function and passing it the category id .
I have also created a cutdown version of the populate function to see if this helped.
[CODE]
function popu()
}
var list = store[number];
var box2 = document.forms[0].subCat;
box2.options.length = 0;
for(i=0;i<list.length;i+=2)
{
box2.options[i/2] = new Option(list[i],list[i+1]);
}
}
Thanks in advance