PDA

View Full Version : dynamically linked listbox


Deb
01-30-2000, 12:18 PM
I'm trying to create 2 listboxes so that when I select something in the first, the second box changes to appropriate values relating to the first box. I'm not familiar with JavaScript, the routine runs, but I keep getting the error, "document.f1.model is not an object"<BR><BR>Here's the code:<BR><BR><HTML><BR><BODY BGCOLOR="FFFFFF" BACKGROUND="NBSPBACK.JPG"><BR><TITLE>lISTbOX</TITLE><BR><H4><BR><%<BR>If IsObject(Session("_conn")) Then<BR> Set conn = Session("_conn")<BR>Else<BR> Set conn = Server.CreateObject("ADODB.Connection")<BR> conn.open "NBSP","",""<BR> Set Session("_conn") = conn<BR>End If<BR>%><BR><BR><%<BR>Set rsx = Server.CreateObject("ADODB.Recordset")<BR>squery = "Select Manufacturer.name, Cars.Model, Manufacturer.manID as ManID, Cars.carID as ModelID" &_<BR> " From Cars INNER JOIN Manufacturer on Cars.Man = Manufacturer.manID order by manufacturer.Name, Cars.Model"<BR>rsx.Open squery, conn, 3, 3<BR><BR><BR>If rsx.EOF then<BR>Response.Write "No manufacturer.<BR>"<BR>Else<BR>'write the manufacturers listbox...<BR> Response.Write "Manufacturer:<SELECT NAME=""manufacturer"" SIZE=15" & _<BR>" ONCHANGE=""manuselected(this);"" >"<BR>'Write the entry code for the Javascript<BR><BR> sJavaScript = "function manuselected(elem) {" & vbCrlf & _<BR> "for (var i=document.f1.model." & _<BR> "options.length; i >=0; i--) {" & vbCrlf & _<BR> "document.f1.model.options[i]=null;" & _<BR> vbCrlf<BR>Do until rsx.EOF <BR>'is this a new manufacturer?<BR>If sLastManufacturer <> rsx("name") Then<BR>'if so, add an entry to the first listbox<BR>sLastManufacturer = rsx("name")<BR>Response.Write "<OPTION VALUE=" & rsx("manID") & ">" & sLastManufacturer & " </OPTION>"<BR>'and add a new section to the javascript...<BR><BR> sJavaScript = sJavaScript & "}" & vbCrlf & _<BR> " if (elem.options[elem.selectedIndex].value==" & _<BR> rsx("manID") & ") {" & vbCrlf<BR> End If<BR><BR><BR>'and add a new model line to the javascript<BR>sJavaScript = sJavaScript & _<BR>"document.f1.model.options[document." & _<BR>"f1.model.options.length] = new Option ('" & _<BR>rsx("model") & "','" & rsx("modelID") & "');" & _<BR>vbCrlf<BR>rsx.MoveNext<BR>Loop<BR>'finish the manufacturer listbox...<BR>Response.Write "</SELECT>"<BR>'create the models listbox...<BR>Response.Write "<SELECT NAME=""model"" size=15>"<BR>Response.Write "<OPTION>[none currently selected]</OPTION>"<BR>Response.Write "</SELECT>"<BR>'put the last line on the javascript and write it out...<BR>sJavaScript = sJavaScript & vbCrlf & "}" & vbCrlf & "}"& vbCrlf<BR>Response.Write "<SCR" & "IPT LANGUAGE=""JavaScript"">"& vbCrlf<BR>Response.Write sJavaScript & vbCrlf & "</SCR" & "IPT>" & vbCrlf<BR>End If<BR>rsx.Close<BR>Set rsx = Nothing<BR>%><BR><BR></BODY><BR></HTML><BR><BR>Thanks, for the help.<BR><BR>