Hi,
I'm trying to get my listboxes to work with the following data:
rsWT is my recordset
WorkTypeID WorkType AssessCategoryID AssessCategory
1 Telephone 1 Energy
1 Telephone 2 Service
2 Correspondence 1 Energy
2 Correspondence 1 Energy
The code is
<script Language="JavaScript">
// start of listbox array
var WorkType;
var WorkTypeOption = new Array();
function init(){
//to initialize
WorkTypeOption ={WorkTypeList: [
<%
dim tWorkType
dim tAssCategory
rsWT.MoveFirst
Do Until rsWT.EOF
If tWorkType <> rsWT("WorkTypeID") Then 'If not equal to previous, than start a new array element
%>
{WorkType: "<%=rsWT("WorkTypeID")%>",AssCategory: [
<%
tWorkType = rsWT("workTypeID")
End If
Response.Write """" & rsWT("AssessCategoryID") & ";" & rsWT("AssessCategory") & """" 'add the assessment category to inner array
rsWT.MoveNext
'end array block
If Not rsWT.EOF Then
'If block completed
If tWorkType <> rsWT("workTypeID") Then 'If next not equal to current, end the array element
Response.Write "]},"
Else
'put in comma, add next element
Response.Write ","
End If
Else
'finish the last block
Response.Write "]}"
End If
Loop
'end the whole array
Response.Write "]};"
%>
}
//change day function
function changeAssCat(elem){
var j, workType, cboAssCat;
cboAssCat = document.frmAssess.cboAssCat
if(elem.selectedIndex == 0)
return false;
cboAssCat.options.text = new Option("Please Select","")
//Clear the second list box
for (i = cboAssCat.options.length; i >= 1; i--) cboAssCat.options[i-1] = null;
cboAssCat.selectedIndex = 1;
//get work type
cboAssCat = elem.selectedIndex=0;
alert (cboAssCat);
//
for(j=0; j<WorkTypeOption.WorkTypeList[WorkType].AssCategory.length; j++){
cboAssCat.options[j] = new Option(WorkTypeOption.WorkTypeList[WorkType].AssCategory[j],"");
}
}
With the code in the body:
<tr>
<td width="300" height="25">
<div align="right">Work Type:
<select name="cboWrkType" class="tlb" onChange="changeAssCat(this);">
<option>Please select</option>
<%
rsWT.MoveFirst
tWorkType = ""
Do Until rsWT.EOF
If tWorkType <> rsWT("workTypeID") Then
%>
<option value ="<%=rsWT("workTypeID")%>"><%=rsWT("workTyp")%></option>
<%
tWorkType = rsWT("workTypeID")
End If
rsWT.MoveNext
Loop
%>
</select>
</div>
</td>
</tr>
<tr>
<td width="300" height="25">
<div align="right">Assessment Category:
<select name="cboAssCat" class="tlb">
<option>Please Select </option>
</select>
</div>
</td>
</tr>
<tr>
I'm getting an error :
error 'worktypeoption.worktypelist' is null or not an object
Can anyone shed some light????
Thanks
I'm trying to get my listboxes to work with the following data:
rsWT is my recordset
WorkTypeID WorkType AssessCategoryID AssessCategory
1 Telephone 1 Energy
1 Telephone 2 Service
2 Correspondence 1 Energy
2 Correspondence 1 Energy
The code is
<script Language="JavaScript">
// start of listbox array
var WorkType;
var WorkTypeOption = new Array();
function init(){
//to initialize
WorkTypeOption ={WorkTypeList: [
<%
dim tWorkType
dim tAssCategory
rsWT.MoveFirst
Do Until rsWT.EOF
If tWorkType <> rsWT("WorkTypeID") Then 'If not equal to previous, than start a new array element
%>
{WorkType: "<%=rsWT("WorkTypeID")%>",AssCategory: [
<%
tWorkType = rsWT("workTypeID")
End If
Response.Write """" & rsWT("AssessCategoryID") & ";" & rsWT("AssessCategory") & """" 'add the assessment category to inner array
rsWT.MoveNext
'end array block
If Not rsWT.EOF Then
'If block completed
If tWorkType <> rsWT("workTypeID") Then 'If next not equal to current, end the array element
Response.Write "]},"
Else
'put in comma, add next element
Response.Write ","
End If
Else
'finish the last block
Response.Write "]}"
End If
Loop
'end the whole array
Response.Write "]};"
%>
}
//change day function
function changeAssCat(elem){
var j, workType, cboAssCat;
cboAssCat = document.frmAssess.cboAssCat
if(elem.selectedIndex == 0)
return false;
cboAssCat.options.text = new Option("Please Select","")
//Clear the second list box
for (i = cboAssCat.options.length; i >= 1; i--) cboAssCat.options[i-1] = null;
cboAssCat.selectedIndex = 1;
//get work type
cboAssCat = elem.selectedIndex=0;
alert (cboAssCat);
//
for(j=0; j<WorkTypeOption.WorkTypeList[WorkType].AssCategory.length; j++){
cboAssCat.options[j] = new Option(WorkTypeOption.WorkTypeList[WorkType].AssCategory[j],"");
}
}
With the code in the body:
<tr>
<td width="300" height="25">
<div align="right">Work Type:
<select name="cboWrkType" class="tlb" onChange="changeAssCat(this);">
<option>Please select</option>
<%
rsWT.MoveFirst
tWorkType = ""
Do Until rsWT.EOF
If tWorkType <> rsWT("workTypeID") Then
%>
<option value ="<%=rsWT("workTypeID")%>"><%=rsWT("workTyp")%></option>
<%
tWorkType = rsWT("workTypeID")
End If
rsWT.MoveNext
Loop
%>
</select>
</div>
</td>
</tr>
<tr>
<td width="300" height="25">
<div align="right">Assessment Category:
<select name="cboAssCat" class="tlb">
<option>Please Select </option>
</select>
</div>
</td>
</tr>
<tr>
I'm getting an error :
error 'worktypeoption.worktypelist' is null or not an object
Can anyone shed some light????
Thanks