Link to home
Start Free TrialLog in
Avatar of VAN
VAN

asked on

Need help w/ dynamic, dependent dropdown boxes

I'm having trouble with these 3 dynamic, dependent dropdown boxes. The way it should work, is you choose a valule from dropdown #1, and then dropdown #2 is populated with appropriate values. You may then make a selection from dropdown #2, and dropdown #3 is populated with appropriate values.

It works as it should, but only the first time around. If you make a backwards choice. eg; youve selected a value from all 3 boxes and decide to go back to choose a new first value), the values for catXid are not being reset. Therefore, if I have chosen Val1, Val2, and Val3 and then go back to choose Val1a, VAL3 is still showing as selected. Hope this makes sense.


Heres what I have...........


<%
cat1id = Request.Form("cat1id")
cat2id = Request.Form("cat2id")
cat3id = Request.Form("cat3id")
%>

<form method=post action=test.asp name=theform>

<select name=cat1id onChange=this.form.submit();resetfields(this);>
  <option value=0>Choose a Category</option>
<%
   Set cat1RS = dbCon1.Execute("SELECT * FROM cat1 WHERE CatName <> """" ORDER BY CatName ASC")

   While NOT cat1RS.EOF

Response.Write("<option value="& cat1RS("ID") &"")
    If cat1RS("ID")*1 = cat1id*1 Then
        Response.Write(" SELECTED")
    End If
Response.Write(">"& cat1RS("CatName") &"</option>" & vBnewline & "")
    cat1RS.MoveNext

    wend
%>
</select>

<select name=cat2id onChange=this.form.submit();resetfields(this);>
  <option value=0 selected>No Sub-Category</option>
<%
If cat1id <> "0" Then
Set cat2RS = dbCon1.Execute("SELECT * FROM cat2 WHERE CatName <> """" AND ParentID = "& cat1id &" ")

    While NOT cat2RS.EOF
Response.Write("<option value='"& cat2RS("ID") &"'")
    If cat2RS("ID")*1 = cat2id*1 Then
        Response.Write(" SELECTED")
    End If
Response.Write(">"& cat2RS("CatName") &"</option>" & vBnewline & "")
    cat2RS.MoveNext
    wend
End If
%>
</select>

<select name=cat3id onChange=this.form.submit();>
  <option value=0 selected>No Sub-Category</option>
<%
If cat2id <> "0" Then
Set cat3RS = dbCon1.Execute("SELECT * FROM cat3 WHERE CatName <> """" AND ParentID = "& cat2id &" ")
    While NOT cat3RS.EOF
Response.Write("<option value='"& cat3RS("ID") &"'")
    If cat3RS("ID")*1 = cat3id*1 Then
        Response.Write("SELECTED")
    End If
Response.Write(">"& cat3RS("CatName") &"</option>" & vBnewline & "")
    cat3RS.MoveNext
    wend
End If
%>
</select>
</form>
ASKER CERTIFIED SOLUTION
Avatar of Shailesh15
Shailesh15

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VAN
VAN

ASKER

I dunno how the heck you understood what I was asking, but your solution works perfectly. Thanks!
Glad to help--:)