sunrise
05-22-2003, 07:14 AM
How do I get the value of a dropdown box called Animal1 into the variable iSpecies? A user select an Animal. Based on what was selected, the Species for that animal type are filled in the Species dropdown box.
The Animal1 dropdown has the following code.
<select id=Animal1 name=Animal1 onchange="fillSpecies();">
<option selected value="">None Selected</option>
<%
sql = "SELECT * from tblType order by typeName"
set rsType = server.CreateObject("ADODB.Recordset")
rsType.Open sql, mConn
do while not rsType.EOF
if trim(rsType("TypeNum")) = trim(sType) then
Response.Write("<option selected value=" & rsType("TypeNum") & ">" & rsType("TypeName"))
else
Response.Write("<option value=" & rsType("TypeNum") & ">" & rsType("TypeName"))
end if
rsType.MoveNext
loop
rsType.Close
set rsType = nothing
set sql = nothing
%>
</select>
The onchange function to fill the Species dropdown box. The variable iSpecies is within the ASP part and not sure how to get the value from the form.
function fillSpecies()
{
<%
set rs2 = (Server.CreateObject("ADODB.Recordset"))
iSpecies = ("document.UserForm.Animal1.selectedIndex")
rs2.Open "SELECT * from tblAnimals where Type = " + iSpecies, mConn
n = 0
do while not rs2.EOF
Response.Write "document.UserForm.Species1[" & n & "] = new Option('" + Replace(rs2("Common_Name"), "'", "'") + "'," & rs2("AnimalID") & ");"
rs2.MoveNext
n = n + 1
loop
rs2.Close
%>
}
The Animal1 dropdown has the following code.
<select id=Animal1 name=Animal1 onchange="fillSpecies();">
<option selected value="">None Selected</option>
<%
sql = "SELECT * from tblType order by typeName"
set rsType = server.CreateObject("ADODB.Recordset")
rsType.Open sql, mConn
do while not rsType.EOF
if trim(rsType("TypeNum")) = trim(sType) then
Response.Write("<option selected value=" & rsType("TypeNum") & ">" & rsType("TypeName"))
else
Response.Write("<option value=" & rsType("TypeNum") & ">" & rsType("TypeName"))
end if
rsType.MoveNext
loop
rsType.Close
set rsType = nothing
set sql = nothing
%>
</select>
The onchange function to fill the Species dropdown box. The variable iSpecies is within the ASP part and not sure how to get the value from the form.
function fillSpecies()
{
<%
set rs2 = (Server.CreateObject("ADODB.Recordset"))
iSpecies = ("document.UserForm.Animal1.selectedIndex")
rs2.Open "SELECT * from tblAnimals where Type = " + iSpecies, mConn
n = 0
do while not rs2.EOF
Response.Write "document.UserForm.Species1[" & n & "] = new Option('" + Replace(rs2("Common_Name"), "'", "'") + "'," & rs2("AnimalID") & ");"
rs2.MoveNext
n = n + 1
loop
rs2.Close
%>
}