the error is happening at line 25 which is the blank line just below MyDept(i)
and i basically removed my array values MyDept and MyID and it doesnt error so i gather it is something to do with the way i am trying to put my data into them from the database
can anyone explain how this is done or show me what the issue is with my code as i couldnt find an answer on google.
russell_g_1
09-11-2005, 11:34 AM
i think the problem is that you haven't said that your arrays are arrays. you need to stick emtpy brackets on the end of the names when you declare them. and then you need to redim them to the right size once you know what it is. here's an example...
set myRs = createobject("ADODB.recordset")
myRs.Open SQL,"DATABASE=filesys1;UID=sa;PWD=qwertyuiop;DSN=filesys1", 1, 3
set rs = myRs
if err then
runSQL = false
response.write err.description
else
runSQL = true
end if
end function
%>
buntine
09-11-2005, 08:06 PM
It would be best to set an explicit size for the array or redimension it after the size has been established.
Set rsgeolink2 = Server.CreateObject("ADODB.Recordset")
Set rsgeolink = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT Dept_ID, [Dept_Name] FROM Department"
Dim MyDept() ' An array of the departments
Dim MyID() ' An array of the dept id
i = 0 ' Used to create a unique id for each array value
It may also be more efficient (or just cleaner) to use a for loop if you want a incrementing variable.
For i = 0 To rsgeolink.RecordCount - 1
...
Next
Regards.
minority
09-12-2005, 04:13 AM
double post
minority
09-12-2005, 04:17 AM
its okay wasnt thinking i meant to do it within a javascript array after all ...
although i can not get it to work correctly i am not sure if it is my javascript or my asp that is creating the issues.
<!--#include file="../../include/connected.asp"--><html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
Set rsgeolink2 = Server.CreateObject("ADODB.Recordset")
Set rsgeolink = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM Document_Type"
strSQL2 = "SELECT Sub_ID, Sub_Name, Dept_ID, Doc_Type_ID FROM Doc_Sub_Category"
rsgeolink.open strSQL, strCon
%>
<script type="text/javascript">
<!--
<!--First array are your "dept_x" variables, shown below: -->
var docs=[<%do until rsgeolink.EOF %>
[<%for each x in rsgeolink.Fields%><%=needcomma%>"<%=x.value%>"<%needcomma = ","%><%next%>]<%rsgeolink.MoveNext%><%needcomma = ""%><%loop%><%rsgeolink.close%>
];
var ids=[<%rsgeolink.open strSQL2, strCon%> <%Do While not rsgeolink.EOF%>
["<%=rsgeolink("Sub_ID")%>","<%=rsgeolink("Sub_Name")%>","<%=rsgeolink("Dept_ID")%>","<%=rsgeolink("Doc_Type_ID")%>"]<%rsgeolink.movenext%><%loop%><%rsgeolink.Close%>
];
function Box2(idx) {
var f=document.myform;
f.box2.options.length=null;
f.box2.options[0]=new Option("Select Document Type", 0);
for(i=1; i<=docs.length; i++) {
if (docs[i-1][idx+2] == 'yes')
f.box2.options[i]=new Option(docs[i][1], docs[i][0]); // if it's yes creat the option docs[i][0] = type_id docs[i][1] = type_name
}
Box3("0"); //calls the function to create third box options with value of 0 (leaves box disabled since no option is selected)
}
function Box3(idx) {
var j=1;
var f=document.myform;
f.box3.options.length=null; //erases current values
f.box3.options[j] = new Option("Select Document ID",0)
f.box3.disabled = true; //makes sure box starts disabled
for(i=0; i<ids.length; i++) {//loops through the ids array
if (ids[i][2] = f.box1.selectedIndex && ids[i][3] = f.box2.selectedIndex){ //returns true if ids[i][2] = dept_id and ids[i][3] = type_id (both of the values for selected items in boxes 1 + 2
if (f.box3.disabled){ //enables box if disabled
f.box3.disabled = false;
}
f.box3.options[j]=new Option(ids[i][1], ids[i][0]); //creates box option
j += 1;
}
}
//-->
</script>
var ids=[
["13","Electronic Down Hole BTR","0","17"]
["1","Health and Safety Policy","10","6"]
["2","Audit Reports","10","6"]
["3","responsible Personnel","10","6"]
["4","Accident Form","10","11"]
["5","Accident Log","10","11"]
["6","manual handling","10","13"]
["7","electrical safety","10","13"]
["8","COSHH","10","13"]
["9","Minutes","10","14"]
["10","Reports","10","14"]
["11","Inspection Reports","10","15"]
["12","Certification","10","15"]
];
function Box2(idx) {
var f=document.myform;
f.box2.options.length=null;
f.box2.options[0]=new Option("Select Document Type", 0);
for(i=1; i<=docs.length; i++) {
if (docs[i-1][idx+2] == 'yes')
f.box2.options[i]=new Option(docs[i][1], docs[i][0]); // if it's yes creat the option docs[i][0] = type_id docs[i][1] = type_name
}
Box3("0"); //calls the function to create third box options with value of 0 (leaves box disabled since no option is selected)
}
function Box3(idx) {
var j=1;
var f=document.myform;
f.box3.options.length=null; //erases current values
f.box3.options[j] = new Option("Select Document ID",0)
f.box3.disabled = true; //makes sure box starts disabled
for(i=0; i<ids.length; i++) {//loops through the ids array
if (ids[i][2] = f.box1.selectedIndex && ids[i][3] = f.box2.selectedIndex){ //returns true if ids[i][2] = dept_id and ids[i][3] = type_id (both of the values for selected items in boxes 1 + 2
if (f.box3.disabled){ //enables box if disabled
f.box3.disabled = false;
}
f.box3.options[j]=new Option(ids[i][1], ids[i][0]); //creates box option
j += 1;
}
}
//-->
</script>
</head>
<body>
<form name="myform" method="post" action="#">
<select name="box1" onchange="Box2(this.selectedIndex)">
<option value="1" > Quality Management</option>
<option value="2" > Sales and Maketing</option>
<option value="3" > Design and Development</option>
<option value="4" > Purchasing</option>
<option value="5" > Manufacturing</option>
<option value="6" > Customer Support</option>
<option value="7" > Administration and Finance</option>
<option value="8" > Operations and Rentals</option>
<option value="9" > Personnel</option>
<option value="10" > Health and Safety</option>
Any help in this part would be greaat as it doing my nut in.
seems to be at this point it errors out at
<select name="box1" onchange="Box2(this.selectedIndex)">
for some reason.
minority
09-13-2005, 05:24 AM
has no one got any ideas?
russell_g_1
09-14-2005, 01:14 PM
what's it all supposed to do?
HaganeNoKokoro
09-14-2005, 01:17 PM
You need commas between array items var ids=[
["13","Electronic Down Hole BTR","0","17"],
["1","Health and Safety Policy","10","6"],
["2","Audit Reports","10","6"],
["3","responsible Personnel","10","6"],
["4","Accident Form","10","11"],
["5","Accident Log","10","11"],
["6","manual handling","10","13"],
["7","electrical safety","10","13"],
["8","COSHH","10","13"],
["9","Minutes","10","14"],
["10","Reports","10","14"],
["11","Inspection Reports","10","15"],
["12","Certification","10","15"]
];(also happening in the docs array)
minority
09-15-2005, 10:23 AM
cheers found it lol
about a hour ago...taking me this long to come back to the thread.
webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved.