...

View Full Version : dynamic dropdown help



esthera
08-16-2005, 12:14 PM
I am trying to make a dynamic drowdown where the user chooses number type , he then gets all the state options fromt the db that match the number type, then based on state he gets area code, adn based on area code he gets local exchange.

I have it working for the first 2 but i'm getting stuck on the third.

You can see it at
http://www.awebforyou.com/dselect/plandropdowns.asp
and here is my code copied in.
(the includes is just the connection and the function openrs which just opens the recordset with the sql passed in)


<% response.buffer=false %>
<!--#include file=openconn.asp-->
<!--#include file=common.asp-->



<html>

<head>

<title>Test</title>

<script language="JavaScript" defer="true">
<%

Selnumbertypeid = "<select name=" & chr(34) & "numbertypeid" & chr(34) & " onchange=" & chr(34) & "javascrpt:ShowSubMenu(this.form.numbertypeid.value);" & chr(34) & ">"
numbertypeList = ""
SqlStr = "select numbertypeid,type from numbertype"
openrs objrs,sqlstr
While Not objrs.Eof
Selnumbertypeid = Selnumbertypeid & "<option value=" & chr(34) & objrs("numbertypeid") & chr(34) & ">" & objrs("type") & "</option>"
numbertypeList = numbertypeList & objrs("numbertypeid") & "|"
objrs.MoveNext
Wend
objrs.Close
Selnumbertypeid = Selnumbertypeid & "</select>"

Response.Write "function ShowSubMenu(TheMenu)" & chr(13) & chr(10) & _
"{" & chr(13) & chr(10) & _
"switch(TheMenu)" & chr(13) & chr(10) & _
"{" & chr(13) & chr(10)
' response.write "numberlist:" & numbertypeList & "endnumbertypelist"
'Create your sub category menus
'We will run a query to get the sub categories for each main category
'Trim the last | off the MainCatList
numbertypeList = Left(numbertypeList,Len(numbertypeList)-1)
numbertypeArr = Split(numbertypeList,"|")
For x = 0 to Ubound(numbertypeArr)
Selstateid = "<select name=\" & chr(34) & "stateid\" & chr(34)& " onchange=\" & chr(34) & "javascrpt:ShowareaMenu(this.form.stateid.value);\" & chr(34) & ">"
'
SqlStr = "select stateid,state from states where numbertypeid='" & numbertypeArr(x) & "'"
' response.write sqlstr
stateidlist=""
openrs objrs,sqlstr
While Not objrs.Eof

Selstateid = Selstateid & "<option value=\" & chr(34) & objrs("stateid") & "\" & chr(34) & ">" & objrs("state") & "</option>"
stateidList = stateidList & objrs("stateid") & "|"
objrs.MoveNext
Wend
objrs.Close
Selstateid = Selstateid & "</select>"

Response.Write "case " & chr(34) & numbertypeArr(x) & chr(34) & ":" & chr(13) & chr(10) & _
"SubCatDiv.style.display = 'block';" & chr(13) & chr(10) & _
"SubCatDiv.innerHTML=" & chr(34) & Selstateid & chr(34) & ";" & chr(13) & chr(10) & _
"break" & chr(13) & chr(10)

Next

Response.Write "}}"
Response.Write "function ShowareaMenu(TheMenu)" & chr(13) & chr(10) & _
"{" & chr(13) & chr(10) & _

"switch(TheMenu)" & chr(13) & chr(10) & _
"{" & chr(13) & chr(10)
' response.write "stateidlist:" & stateidList & "endstateidlist"
stateidList = Left(stateidList,Len(stateidList)-1)

stateArr = Split(stateidList,"|")
For x = 0 to Ubound(stateArr)
'& " onchange=" & chr(34) & "javascrpt:ShowSubMenu(this.form.stateid.value);" & chr(34)
Selareacode= "<select name=\" & chr(34) & "areacode\" & chr(34) & ">"
SqlStr = "select areacode from areacodes where stateid='" & stateArr(x) & "'"
'response.write sqlstr
openrs objrs,sqlstr
While Not objrs.Eof

Selareacode = Selareacode & "<option value=\" & chr(34) & objrs("areacode") & "\" & chr(34) & ">" & objrs("areacode") & "</option>"
objrs.MoveNext
Wend
objrs.Close
Selareacode = Selareacode & "</select>"

Response.Write "case " & chr(34) & stateArr(x) & chr(34) & ":" & chr(13) & chr(10) & _
"areaDiv.style.display = 'block';" & chr(13) & chr(10) & _
"areaDiv.innerHTML=" & chr(34) & Selareacode & chr(34) & ";" & chr(13) & chr(10) & _
"break" & chr(13) & chr(10)

Next

Response.Write "}}"

%>
</script>

</head>

<body>

<form name="TheForm" method="post" action="MultiDynSelect.asp">
<div id="MainCatDiv"><%=Selnumbertypeid%></div>
<div id="SubCatDiv" style="display:none;"></div>
<div id="areaDiv" style="display:none;"></div>
</form>


</body>
</html>

<%
Set objrs = Nothing

%>



It's a combination of asp and javascript -- I would appreciate any help you can give.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum