luv2smile
07-21-2003, 11:41 AM
Here is my problem: I have 2 drop down lists that use asp to pull in the data and javascript to make the 2nd one dependent on the first drop down list. Ex. The first is a list of manufacturers and then the list of models depends on which manufacturer the user selects.
Ok, that works fine on the search page....the user chooses to search by model/man.
But then on a seperate page, I want to bring in the values the user selected on the search page and re-create the drop down lists so the user can change their selections, but so that was they selected is highlighted when the page is loaded.
The variables are being passed to the seperate page because I can make the selected option the one the user previously selected....but when I do that, the rest of the box doesn't work correctly.
I can bring in the Manufacturer, but the model list appears blank until the user changes the manufacturer...then it works fine.
Do I need 2 functions....one to fill the drop down box and one to change it?
Help......this is my first experience at really using javascript.
Here is the search page where the user makes his selections:
<!-- #include virtual="/crtest/authenticate.asp" -->
<HTML>
<!-- #include virtual="/crtest/Header.htm" -->
<HEAD>
<%
'crtech-inv
set conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=f:\web\database\crtest\equip.mdb"
Set comInv = Server.CreateObject("ADODB.Command")' Open the connection here
comInv.ActiveConnection = conn
comInv.CommandType = 1 ' SQL Statement, not a table or canned routine
%>
<CENTER><H1>CSS Equipment Search</H1></CENTER>
<%
' Query to get a list of valid Manufacturer Values
comInv.CommandText = "SELECT DISTINCT Equipment.Manufacturer AS Manufacturer FROM Equipment"
Set ManList = comInv.Execute
' Query to get a list of valid Manufacturer/ModelNumber combinations
comInv.CommandText = "SELECT DISTINCT Equipment.Manufacturer AS Manufacturer, Equipment.ModelNumber AS ModelNumber FROM Equipment"
Set ManModList = comInv.Execute
' Query to get a list of other valid Department Values
comInv.CommandText = "SELECT DISTINCT DeptCode FROM Departments ORDER BY DeptCode"
Set DeptList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT LocalName FROM Equipment ORDER BY LocalName"
Set LocalList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT UVAAssetNumber FROM Equipment ORDER BY UVAAssetNumber"
Set AssetList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT UserOwner FROM Equipment ORDER BY UserOwner"
Set UserList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT Location FROM Equipment ORDER BY Location"
Set LocationList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT Equipment.Manufacturer FROM Equipment"
Set ManuList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT Equipment.ModelNumber FROM Equipment"
Set ModelList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT ID,Description FROM EquipTypes"
Set EqTypeList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT Equipment.Location FROM Equipment"
Set LocList = comInv.Execute
%>
<script language="Javascript">
var ManModList = new Array();
<%
Index = 0
Do While NOT ManModList.EOF
Manufacturer = ManModList("Manufacturer")
If Manufacturer <> "" Then
ModelNumber = ManModList("ModelNumber")
If ModelNumber <> "" Then
Response.Write " ManModList[" & Index & "] ='" & Manufacturer & "|" & ModelNumber & "'" & vbCrLf
Index = Index + 1
End If
End If
ManModList.MoveNext
Loop
%>
function PopulateData( select, name, array ) {
string = "";
// 0 - will display the new options only
// 1 - will display the first existing option plus the new options
count = 0;
// Clear the old list (above element 0)
select.options.length = count;
// Place all matching categories into Options.
for( i = 0; i < array.length; i++ ) {
string = array[i].split( "|" );
if( string[0] == name ) {
select.options[count++] = new Option( string[1] );
}
}
}
</script>
<TITLE>crtech Equipment Search</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"></font>
<FORM ACTION="./eqresult.asp" METHOD="POST">
<TABLE>
<TR><TD ALIGN="right">Asset Tag (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__UVAAssetNumber" SIZE="30" MAXLENGTH="30">
</TD></TR>
<TR><TD ALIGN="right">Department</TD>
<TD><SELECT NAME="Equipment__Department">
<OPTION selected VALUE="Null">(All)
<%
Do While NOT DeptList.EOF
DeptCode = DeptList("DeptCode")
Response.Write "<OPTION VALUE='" & DeptCode & "'>" & DeptCode & vbCrLf
DeptList.MoveNext
Loop
%>
</SELECT>
</TD></TR>
<TR>
<td ALIGN="right">Manufacturer</td>
<td>
<select name='Manufacturer' style="width:120;" onChange='PopulateData( Model, Manufacturer.options[selectedIndex].text, ManModList )'>
<option selected></option>
<%
Do While NOT ManList.EOF
Manufacturer = ManList("Manufacturer")
If Manufacturer <> "" Then
Response.Write " <OPTION>" & Manufacturer & "</OPTION>" & vbCrLf
End If
ManList.MoveNext
Loop
%>
</select>
</td>
</tr>
<TR>
<td ALIGN="right">Model</td>
<td><select name="Model" style="width:120;">
<option selected></option>
</select>
</td>
</TR>
<TR><TD ALIGN="right">Equipment Type</TD>
<TD><SELECT NAME="Equipment__EquipType">
<OPTION selected VALUE="Null">(All)
<%
Do While NOT EqTypeList.EOF
ID = EqTypeList("ID")
Description = EqTypeList("Description")
Response.Write "<OPTION VALUE='" & ID & "'>" & Description & vbCrLf
EqTypeList.MoveNext
Loop
%>
</SELECT>
</TD></TR>
<TR><TD ALIGN="right">Location</TD>
<TD>
<select name="Equipment__Location">
<option selected value="Null">(All)
<%
Do While NOT LocList.EOF
Location = LocList("Location")
Response.Write "<OPTION VALUE='" & Location & "'>" & Location & vbCrLf
LocList.MoveNext
Loop
%>
</select>
</TD>
</TR>
<TR><TD ALIGN="right">Serial Number (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__SerialNumber" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right">User/Owner (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__UserOwner" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right">Local Name (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__LocalName" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right">IP Address (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__IPAddress" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right">Comments (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__Comments" SIZE="50" MAXLENGTH="255">
</TD></TR>
<TR><TD ALIGN="right">Building Name (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__Building" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" Value="Search All"> </TD>
<TD ALIGN="left" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" VALUE="Search Maintenance Logs"></TD>
</TR><TR>
<TD ALIGN="right" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" VALUE="Reset"></TD>
<TD ALIGN="left" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" Value="Add"></TD>
</TR>
</FORM>
<TR><FORM ACTION = "eqresult.asp" METHOD = "post">
<TD ALIGN="right" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" Value="SearchPC">
<INPUT TYPE="hidden" NAME="Equipment_EquipType" Value = "2">
<INPUT TYPE="hidden" NAME="Equipment_Department" Value = "css-cr">
</TD></FORM>
<FORM ACTION = "eqresult.asp" METHOD = "post">
<TD ALIGN="left" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" Value="SearchMAC">
<INPUT TYPE="hidden" NAME="Equipment_EquipType" Value = "6">
<INPUT TYPE="hidden" NAME="Equipment_Department" Value = "css-cr">
</TD></FORM>
</TR>
</FORM>
</TABLE>
</BODY>
<!-- #include virtual="/crtest/Footer.htm" -->
</HTML>
Ok, that works fine on the search page....the user chooses to search by model/man.
But then on a seperate page, I want to bring in the values the user selected on the search page and re-create the drop down lists so the user can change their selections, but so that was they selected is highlighted when the page is loaded.
The variables are being passed to the seperate page because I can make the selected option the one the user previously selected....but when I do that, the rest of the box doesn't work correctly.
I can bring in the Manufacturer, but the model list appears blank until the user changes the manufacturer...then it works fine.
Do I need 2 functions....one to fill the drop down box and one to change it?
Help......this is my first experience at really using javascript.
Here is the search page where the user makes his selections:
<!-- #include virtual="/crtest/authenticate.asp" -->
<HTML>
<!-- #include virtual="/crtest/Header.htm" -->
<HEAD>
<%
'crtech-inv
set conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=f:\web\database\crtest\equip.mdb"
Set comInv = Server.CreateObject("ADODB.Command")' Open the connection here
comInv.ActiveConnection = conn
comInv.CommandType = 1 ' SQL Statement, not a table or canned routine
%>
<CENTER><H1>CSS Equipment Search</H1></CENTER>
<%
' Query to get a list of valid Manufacturer Values
comInv.CommandText = "SELECT DISTINCT Equipment.Manufacturer AS Manufacturer FROM Equipment"
Set ManList = comInv.Execute
' Query to get a list of valid Manufacturer/ModelNumber combinations
comInv.CommandText = "SELECT DISTINCT Equipment.Manufacturer AS Manufacturer, Equipment.ModelNumber AS ModelNumber FROM Equipment"
Set ManModList = comInv.Execute
' Query to get a list of other valid Department Values
comInv.CommandText = "SELECT DISTINCT DeptCode FROM Departments ORDER BY DeptCode"
Set DeptList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT LocalName FROM Equipment ORDER BY LocalName"
Set LocalList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT UVAAssetNumber FROM Equipment ORDER BY UVAAssetNumber"
Set AssetList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT UserOwner FROM Equipment ORDER BY UserOwner"
Set UserList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT Location FROM Equipment ORDER BY Location"
Set LocationList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT Equipment.Manufacturer FROM Equipment"
Set ManuList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT Equipment.ModelNumber FROM Equipment"
Set ModelList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT ID,Description FROM EquipTypes"
Set EqTypeList = comInv.Execute
comInv.CommandText = "SELECT DISTINCT Equipment.Location FROM Equipment"
Set LocList = comInv.Execute
%>
<script language="Javascript">
var ManModList = new Array();
<%
Index = 0
Do While NOT ManModList.EOF
Manufacturer = ManModList("Manufacturer")
If Manufacturer <> "" Then
ModelNumber = ManModList("ModelNumber")
If ModelNumber <> "" Then
Response.Write " ManModList[" & Index & "] ='" & Manufacturer & "|" & ModelNumber & "'" & vbCrLf
Index = Index + 1
End If
End If
ManModList.MoveNext
Loop
%>
function PopulateData( select, name, array ) {
string = "";
// 0 - will display the new options only
// 1 - will display the first existing option plus the new options
count = 0;
// Clear the old list (above element 0)
select.options.length = count;
// Place all matching categories into Options.
for( i = 0; i < array.length; i++ ) {
string = array[i].split( "|" );
if( string[0] == name ) {
select.options[count++] = new Option( string[1] );
}
}
}
</script>
<TITLE>crtech Equipment Search</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"></font>
<FORM ACTION="./eqresult.asp" METHOD="POST">
<TABLE>
<TR><TD ALIGN="right">Asset Tag (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__UVAAssetNumber" SIZE="30" MAXLENGTH="30">
</TD></TR>
<TR><TD ALIGN="right">Department</TD>
<TD><SELECT NAME="Equipment__Department">
<OPTION selected VALUE="Null">(All)
<%
Do While NOT DeptList.EOF
DeptCode = DeptList("DeptCode")
Response.Write "<OPTION VALUE='" & DeptCode & "'>" & DeptCode & vbCrLf
DeptList.MoveNext
Loop
%>
</SELECT>
</TD></TR>
<TR>
<td ALIGN="right">Manufacturer</td>
<td>
<select name='Manufacturer' style="width:120;" onChange='PopulateData( Model, Manufacturer.options[selectedIndex].text, ManModList )'>
<option selected></option>
<%
Do While NOT ManList.EOF
Manufacturer = ManList("Manufacturer")
If Manufacturer <> "" Then
Response.Write " <OPTION>" & Manufacturer & "</OPTION>" & vbCrLf
End If
ManList.MoveNext
Loop
%>
</select>
</td>
</tr>
<TR>
<td ALIGN="right">Model</td>
<td><select name="Model" style="width:120;">
<option selected></option>
</select>
</td>
</TR>
<TR><TD ALIGN="right">Equipment Type</TD>
<TD><SELECT NAME="Equipment__EquipType">
<OPTION selected VALUE="Null">(All)
<%
Do While NOT EqTypeList.EOF
ID = EqTypeList("ID")
Description = EqTypeList("Description")
Response.Write "<OPTION VALUE='" & ID & "'>" & Description & vbCrLf
EqTypeList.MoveNext
Loop
%>
</SELECT>
</TD></TR>
<TR><TD ALIGN="right">Location</TD>
<TD>
<select name="Equipment__Location">
<option selected value="Null">(All)
<%
Do While NOT LocList.EOF
Location = LocList("Location")
Response.Write "<OPTION VALUE='" & Location & "'>" & Location & vbCrLf
LocList.MoveNext
Loop
%>
</select>
</TD>
</TR>
<TR><TD ALIGN="right">Serial Number (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__SerialNumber" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right">User/Owner (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__UserOwner" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right">Local Name (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__LocalName" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right">IP Address (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__IPAddress" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right">Comments (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__Comments" SIZE="50" MAXLENGTH="255">
</TD></TR>
<TR><TD ALIGN="right">Building Name (Partial match)</TD>
<TD><INPUT TYPE="text" NAME="Equipment__Building" SIZE="30" MAXLENGTH="40">
</TD></TR>
<TR><TD ALIGN="right" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" Value="Search All"> </TD>
<TD ALIGN="left" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" VALUE="Search Maintenance Logs"></TD>
</TR><TR>
<TD ALIGN="right" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" VALUE="Reset"></TD>
<TD ALIGN="left" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" Value="Add"></TD>
</TR>
</FORM>
<TR><FORM ACTION = "eqresult.asp" METHOD = "post">
<TD ALIGN="right" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" Value="SearchPC">
<INPUT TYPE="hidden" NAME="Equipment_EquipType" Value = "2">
<INPUT TYPE="hidden" NAME="Equipment_Department" Value = "css-cr">
</TD></FORM>
<FORM ACTION = "eqresult.asp" METHOD = "post">
<TD ALIGN="left" WIDTH="50%"><INPUT NAME="Submit" TYPE="submit" Value="SearchMAC">
<INPUT TYPE="hidden" NAME="Equipment_EquipType" Value = "6">
<INPUT TYPE="hidden" NAME="Equipment_Department" Value = "css-cr">
</TD></FORM>
</TR>
</FORM>
</TABLE>
</BODY>
<!-- #include virtual="/crtest/Footer.htm" -->
</HTML>