how to populate second dynamic drop down from user selection in first dynamic drop down

ajax , asp United States
  • 13 years ago

    I'm having a problem getting my two dynamic drop down menus to talk to each other.  I can get them both to populate from the db but what I want to do is populate the first one, have the user make a selection from it and then populate the second one using the selected value from the first.  I can't seem to figure out how to get the selected value into the sql string for the second.

    Here's what I've got for the first one:

    <%
    Dim DeltaDates, c, a, x
    strSQL = "SELECT EvalId, EvalDate From DeltaEvals"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open strSQL, cn, 0, 1, &H0001
    DeltaDates = rs.GetRows()
    c = UBound(DeltaDates, 2)
    response.Write ("DeltaDates Array = ")
    for a = 0 to CLng(c)
    response.Write (DeltaDates(0,a)& ",")
    next
    rs.Close
    set rs = nothing
    %>
    <select name="WhichDate" id="WhichDate">
     <option value="">- Select -</option>
     <%for a = 0 to CLng(c)
      %><option value="<%=DeltaDates(0, a)%>"><%=DeltaDates(1, a)%></option><%
     next%>
    </select>

    Any ideas on how I can get the selected value from this one into this sql string for the Xid variable?

    strSQL = "SELECT DeltaTimes.EvalId, * FROM DeltaTimes INNER JOIN DeltaEvals ON DeltaTimes.EvalId = DeltaEvals.EvalId WHERE DeltaTimes.EvalId="&Xid&" AND DeltaTimes.Closed <> True;"

  • 13 years ago

    Hi,

    One way to do this is to add an onclick event to the dropdown box.  First of all, change the "action" of the form so that it posts to itself, then add the bold bit to your <select> tag:

    <%
    Dim DeltaDates, c, a, x
    strSQL = "SELECT EvalId, EvalDate From DeltaEvals"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open strSQL, cn, 0, 1, &H0001
    DeltaDates = rs.GetRows()
    c = UBound(DeltaDates, 2)
    response.Write ("DeltaDates Array = ")
    for a = 0 to CLng(c)
    response.Write (DeltaDates(0,a)& ",")
    next
    rs.Close
    set rs = nothing
    %>
    <select name="WhichDate" id="WhichDate" onclick="formHandler(this);">
     <option value="">- Select -</option>
     <%for a = 0 to CLng(c)
      %><option value="<%=DeltaDates(0, a)%>"><%=DeltaDates(1, a)%></option><%
     next%>
    </select>

    Your formhandler function will simply submit your form and looks like this:

    <script>
    function formhandler(whichForm){
    document.whichForm.submit();
    }
    </script>

    Finally, all you have to do to capture the value of the first dropdown is:
    strSQL = "SELECT DeltaTimes.EvalId, * FROM DeltaTimes INNER JOIN DeltaEvals ON DeltaTimes.EvalId = DeltaEvals.EvalId WHERE DeltaTimes.Closed <> True"
    If Len(Request.Form("WhichDate")) > 0 Then strSQL = strSQL & " DeltaTimes.EvalID = " & Request.Form("WhichDate")
     

  • 12 years ago

    You can use Ajax code to do this.

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter” - Eric Raymond