I have two combo boxes that are populated from a ms access database based on a search field. Each of the combo boxes have their textboxed next to them so when an item within the combobox is selected the textboxs get populated with data from the database for that specific record. I am using the onchange="return chemC_change(frmSelect)" for each combobox. The problem I am having is when I select one of the comboboxes the others text boxes go blank and the other combobox de-populates. I think the other is reaching the eof. The purpose of this code is to search a chemical in my database and show its cooresponding data.
Code:
<%@ Language=VBScript %>
<%Option explicit
Dim conn, connect
set conn=server.CreateObject ("adodb.connection")
connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("ChemComp.mdb") & ";Persist Security Info=False"
conn.Open connect
%>
<html>
<head>
<title>Example combo box</title>
<script language="javascript">
<!--
function chemC_change(frmSelect) {
frmSelect.submit();
}
//-->
</script>
<script language="javascript">
<!--
function chemC_change2(frmSelect2) {
frmSelect2.submit();
}
//-->
</script>
</head>
<body>
<form name="form" method="POST" action="cc2-3.asp">
<div align="center"><strong>Enter Chemical Name:</strong><br>
<input name="test" type="text" value="<%=Request.Form("test")%>">
<input type="submit" name="Submit" value="Submit">
</div>
</form>
<form name="frmSelect" method="POST" action="cc2-3.asp">
<blockquote>
<p> Fiber In Media:<br>
<SELECT name=components LANGUAGE=javascript onchange="return chemC_change(frmSelect)">
<%
Dim oRs, query, rstry, query2, comp_name
Dim MaxTemp, TypeNameC, NoteIDC, AATempC
query2 = "SELECT DISTINCT ComponentName FROM Comp_Chart WHERE ChemicalName ='"& Request.Form("test") & "'"
query2 = query2 & " AND CategoryName = 'FIBER IN MEDIA'"
'query2 = "SELECT DISTINCT ComponentName FROM Comp_Chart WHERE ChemicalName ='"& Request.Form("test") & "'"
'query2 = query2 & "CategoryName = 'FIBER IN MEDIA'";
set oRs = conn.Execute(query2)
query = "SELECT * FROM Comp_Chart WHERE ComponentName ='"& Request.Form("components") & "'"
Set rstry= conn.Execute(query)
' if course is not selected, add firt item telling them to select a first name
comp_name = Request.Form("components") & ""
if comp_name = "" then
Response.Write "<option value='Select a Chemical Name' SELECTED>Select a Chemical Name</option>"
end if
Do while not oRs.EOF
if comp_name = oRs("ComponentName") then 'if this is the selected one then display as selected
Response.Write "<option value= '" & oRs ("ComponentName") & "' SELECTED>"
Response.Write oRs("ComponentName") & "</Option>"
oRs.MoveNext
else
Response.Write "<option value= '" & oRs ("ComponentName") & "'>"
Response.Write oRs("ComponentName") & "</Option>"
oRs.MoveNext
end if
loop
%>
</SELECT>
<%
If rstry.EOF then
MaxTemp = ""
TypeNameC = ""
NoteIDC = ""
AATempC = ""
else
MaxTemp = rstry("MaxOprTemp")
TypeNameC = rstry("TypeName")
NoteIDC = rstry("NoteID")
AATempC = rstry("AATemp")
end if
%>
<input name="textfield" type="text" value="<%=MaxTemp%>" size="10">
<input name="textfield" type="text" value="<%=TypeNameC%>" size="48">
<input name="textfield" type="text" value="<%=NoteIDC%>" size="20">
<input name="textfield" type="text" value="<%=AATempC%>" size="15">
<input type="hidden" name="test" value="<%=Request.Form("test")%>">
</p>
</blockquote>
<%
oRs.Close
Set oRs = nothing
rstry.Close
Set rstry = nothing
%>
</form>
<form name="frmSelect2" method="POST" action="cc2-3.asp">
<blockquote>
<p> Stack Gaskets:<br>
<SELECT name=componentsII LANGUAGE=javascript onchange="return chemC_change2(frmSelect2)">
<%
Dim oRs2, query4, rstry2, query3, comp_name2, componentsII
Dim MaxTemp2, TypeNameC2, NoteIDC2, AATempC2
query3 = "SELECT DISTINCT ComponentName FROM Comp_Chart WHERE ChemicalName ='"& Request.Form("test") & "'"
query3 = query3 & " AND CategoryName = 'STACK GASKETS'"
'query2 = "SELECT DISTINCT ComponentName FROM Comp_Chart WHERE ChemicalName ='"& Request.Form("test") & "'"
'query2 = query2 & "CategoryName = 'FIBER IN MEDIA'";
set oRs2 = conn.Execute(query3)
query4 = "SELECT * FROM Comp_Chart WHERE ComponentName ='"& Request.Form("componentsII") & "'"
Set rstry2= conn.Execute(query4)
' if course is not selected, add firt item telling them to selec a first name
comp_name2 = Request.Form("componentsII") & ""
if comp_name2 = "" then
Response.Write "<option value='Select a Chemical Name' SELECTED>Select a Chemical Name</option>"
end if
Do while not oRs2.EOF
if comp_name2 = oRs2("ComponentName") then 'if this is the selected one then display as selected
Response.Write "<option value= '" & oRs2 ("ComponentName") & "' SELECTED>"
Response.Write oRs2("ComponentName") & "</Option>"
oRs2.MoveNext
else
Response.Write "<option value= '" & oRs2 ("ComponentName") & "'>"
Response.Write oRs2("ComponentName") & "</Option>"
oRs2.MoveNext
end if
loop
%>
</SELECT>
<%
if rstry2.EOF THEN
MaxTemp2 = ""
TypeNameC2 =""
NoteIDC2 = ""
AATempC2 = ""
else
MaxTemp2 = rstry2("MaxOprTemp")
TypeNameC2 = rstry2("TypeName")
NoteIDC2 = rstry2("NoteID")
AATempC2 = rstry2("AATemp")
end if
%>
<input name="textfield" type="text" value="<%=MaxTemp2%>" size="10">
<input name="textfield" type="text" value="<%=TypeNameC2%>" size="48">
<input name="textfield" type="text" value="<%=NoteIDC2%>" size="20">
<input name="textfield" type="text" value="<%=AATempC2%>" size="15">
<input type="hidden" name="test" value="<%=Request.Form("test")%>">
<%
oRs2.Close
Set oRs2 = nothing
rstry2.Close
Set rstry2 = nothing
%>
</p>
</blockquote>
</form>
<p> </p>
</body>
</html>