Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2004
    Posts
    17

    Angry Unanswered: Submitting Query automatically

    Alright I've set up three dynamic drop down boxes.

    Box1

    Box2

    Box3

    I know that I will need to do the java behavior onChange on Box3

    How would i work it to search my database for the record matching box3 (I've set it up so that only one record will result from the final dropdown)
    and put the other information in that record into a table along with a picture (I've referenced the picture in a column of the database).

    Some of the columns I need displayed are numerical values and some are text values.

    Special thanks to BullSchmidt for his tutorial on dropdown list boxes

    J.
    Last edited by jwortley; 07-14-04 at 21:59.

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    I'd set the onchange event to submit the form that contains box3. Then I would do a request.form to get the value of box 3 and execute the query.

  3. #3
    Join Date
    Jun 2004
    Posts
    17
    How would I go about grabbing the value from box three?

    I would like to have it set up so that when i hit the submit button another page would come up with the results from the query.
    Last edited by jwortley; 07-15-04 at 20:30.

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Do you mean a popup window appears??

    If so then I would use the javascript in the on change event to opent he window and create a url with a query string containing the search value from box three in it.

    If you mean you want the submit to go to a new page within the same browser then you just set the action value of the form to the page you want to go to and to get the value ofr box 3 your just do a request.form.

  5. #5
    Join Date
    Jun 2004
    Posts
    17

    Post Almost there

    Ok i have everything set up thank you for the assistance.

    One problem I am having.

    It seems that if there is one selection in a child listbox, it won't refresh the grandchild listbox automatically, and when it is clicked nothing happens.

    Is there anyway to generate the code to refresh the grandchild listbox with the only possible selection from the child listbox.

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="Connections/ProtoUcamara.asp" -->
    
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    <!--
    
    var arrDynaList = new Array();
    var arrDL1 = new Array();
    
    arrDL1[1] = "lstOrder";               // Name of parent list box
    arrDL1[2] = "form1";                  // Name of form containing parent list box
    arrDL1[3] = "lstFamily";               // Name of child list box
    arrDL1[4] = "form1";                  // Name of form containing child list box
    arrDL1[5] = arrDynaList;
      
    <%
    Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS
    
    txtDynaListRelation = "Order_ID"      ' Name of recordset field relating to parent
    txtDynaListLabel = "Labels"            ' Name of recordset field for child Item Label
    txtDynaListValue = "Family_ID"            ' Name of recordset field for child Value
    Set oDynaListRS = rsFamily             ' Name of child list box recordset
      
    Dim varDynaList
    varDynaList = -1
    
    Dim varMaxWidth
    varMaxWidth = "1"
    
    Dim varCheckGroup
    varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value
    
    Dim varCheckLength
    varCheckLength = 0
    
    Dim varMaxLength
    varMaxLength = 0
    
    While (NOT oDynaListRS.EOF)
    
     If (varCheckGroup <> oDynaListRS.Fields.Item(txtDynaListRelation).Value) Then
      If (varCheckLength > varMaxLength) Then
       varMaxLength = varCheckLength
      End If
      varCheckLength = 0
     End If
    %>
     arrDynaList[<%=(varDynaList+1)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%>"
     arrDynaList[<%=(varDynaList+2)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%>"
     arrDynaList[<%=(varDynaList+3)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%>"
    <%
     If (len(oDynaListRS.Fields.Item(txtDynaListLabel).Value) > len(varMaxWidth)) Then
      varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value
     End If
     varCheckLength = varCheckLength + 1
     varDynaList = varDynaList + 3
     oDynaListRS.MoveNext()
    Wend
    
    If (varCheckLength > varMaxLength) Then
     varMaxLength = varCheckLength
    End If
    %>
    
    //-->
    </script>
    <script language="JavaScript">
    <!--
    function setDynaList(arrDL){
    
     var oList1 = document.forms[arrDL[2]].elements[arrDL[1]];
     var oList2 = document.forms[arrDL[4]].elements[arrDL[3]];
     var arrList = arrDL[5];
     
     clearDynaList(oList2);
     
     if (oList1.selectedIndex == -1){
      oList1.selectedIndex = 0;
     }
    
     populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);
     return true;
    }
     
    function clearDynaList(oList){
    
     for (var i = oList.options.length; i >= 0; i--){
      oList.options[i] = null;
     }
     
     oList.selectedIndex = -1;
    }
     
    function populateDynaList(oList, nIndex, aArray){
    
     for (var i = 0; i < aArray.length; i= i + 3){
      if (aArray[i] == nIndex){
       oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
      }
     }
    
     if (oList.options.length == 0){
      oList.options[oList.options.length] = new Option("[none available]",0);
     }
     
     oList.selectedIndex = 0;
    }
    
    function Kermy_JS(jsStr) { 
      return eval(jsStr)
    }
    //-->
    </script>
    <script language="JavaScript">
    <!--
    var arrDynaList2 = new Array();
    var arrDL2 = new Array();
    
    arrDL2[1] = "lstFamily";               // Name of parent list box
    arrDL2[2] = "form1";                  // Name of form containing parent list box
    arrDL2[3] = "lstGenus";               // Name of child list box
    arrDL2[4] = "form1";                  // Name of form containing child list box
    arrDL2[5] = arrDynaList2;
      
    <%
    Dim txtDynaListRelation2, txtDynaListLabel2, txtDynaListValue2, oDynaListRS2
    
    txtDynaListRelation2 = "Family_ID"      ' Name of recordset field relating to parent
    txtDynaListLabel2 = "Labels"            ' Name of recordset field for child Item Label
    txtDynaListValue2 = "Genus_ID"            ' Name of recordset field for child Value
    Set oDynaListRS2 = rsGenus             ' Name of child list box recordset
      
    Dim varDynaList2
    varDynaList2 = -1
    
    Dim varMaxWidth2
    varMaxWidth2 = "1"
    
    Dim varCheckGroup2
    varCheckGroup2 = oDynaListRS2.Fields.Item(txtDynaListRelation2).Value
    
    Dim varCheckLength2
    varCheckLength2 = 0
    
    Dim varMaxLength2
    varMaxLength2 = 0
    
    While (NOT oDynaListRS2.EOF)
    
     If (varCheckGroup2 <> oDynaListRS2.Fields.Item(txtDynaListRelation2).Value) Then
      If (varCheckLength2 > varMaxLength2) Then
       varMaxLength2 = varCheckLength2
      End If
      varCheckLength2 = 0
     End If
    %>
     arrDynaList2[<%=(varDynaList2+1)%>] = "<%=(oDynaListRS2.Fields.Item(txtDynaListRelation2).Value)%>"
     arrDynaList2[<%=(varDynaList2+2)%>] = "<%=(oDynaListRS2.Fields.Item(txtDynaListLabel2).Value)%>"
     arrDynaList2[<%=(varDynaList2+3)%>] = "<%=(oDynaListRS2.Fields.Item(txtDynaListValue2).Value)%>"
    <%
     If (len(oDynaListRS2.Fields.Item(txtDynaListLabel2).Value) > len(varMaxWidth)) Then
      varMaxWidth2 = oDynaListRS.Fields.Item(txtDynaListLabel2).Value
     End If
     varCheckLength2 = varCheckLength2 + 1
     varDynaList2 = varDynaList2 + 3
     oDynaListRS2.MoveNext()
    Wend
    
    If (varCheckLength2 > varMaxLength2) Then
     varMaxLength2 = varCheckLength2
    End If
    %>
    
    function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
    }
    //-->
    </script>
    <script language="JavaScript">
    <!--
    
    
    
    var arrDynaList3 = new Array();
    var arrDL3 = new Array();
    
    arrDL3[1] = "lstGenus";               // Name of parent list box
    arrDL3[2] = "form1";                  // Name of form containing parent list box
    arrDL3[3] = "lstSpecies";               // Name of child list box
    arrDL3[4] = "form1";                  // Name of form containing child list box
    arrDL3[5] = arrDynaList3;
      
    <%
    Dim txtDynaListRelation3, txtDynaListLabel3, txtDynaListValue3, oDynaListRS3
    
    txtDynaListRelation3 = "Genus_ID"      ' Name of recordset field relating to parent
    txtDynaListLabel3 = "Labels"            ' Name of recordset field for child Item Label
    txtDynaListValue3 = "Species_ID"            ' Name of recordset field for child Value
    Set oDynaListRS3 = rsSpecies             ' Name of child list box recordset
      
    Dim varDynaList3
    varDynaList3 = -1
    
    Dim varMaxWidth3
    varMaxWidth3 = "1"
    
    Dim varCheckGroup3
    varCheckGroup3 = oDynaListRS3.Fields.Item(txtDynaListRelation3).Value
    
    Dim varCheckLength3
    varCheckLength3 = 0
    
    Dim varMaxLength3
    varMaxLength3 = 0
    
    While (NOT oDynaListRS3.EOF)
    
     If (varCheckGroup3 <> oDynaListRS3.Fields.Item(txtDynaListRelation3).Value) Then
      If (varCheckLength3 > varMaxLength3) Then
       varMaxLength3 = varCheckLength3
      End If
      varCheckLength3 = 0
     End If
    %>
     arrDynaList3[<%=(varDynaList3+1)%>] = "<%=(oDynaListRS3.Fields.Item(txtDynaListRelation3).Value)%>"
     arrDynaList3[<%=(varDynaList3+2)%>] = "<%=(oDynaListRS3.Fields.Item(txtDynaListLabel3).Value)%>"
     arrDynaList3[<%=(varDynaList3+3)%>] = "<%=(oDynaListRS3.Fields.Item(txtDynaListValue3).Value)%>"
    <%
     If (len(oDynaListRS3.Fields.Item(txtDynaListLabel3).Value) > len(varMaxWidth3)) Then
      varMaxWidth3 = oDynaListRS3.Fields.Item(txtDynaListLabel3).Value
     End If
     varCheckLength3 = varCheckLength3 + 1
     varDynaList3 = varDynaList3 + 3
     oDynaListRS3.MoveNext()
    Wend
    
    If (varCheckLength3 > varMaxLength3) Then
     varMaxLength3 = varCheckLength3
    End If
    %>
    
    </script>
    
    <style type="text/css">
    <!--
    @import url("StylesUcamara.css");
    -->
    </style>
    </head>
    <p><BODY bgColor=#ffffff link=darkblue vLink=green aLink=purple>
    <TBODY><TR><TD bgColor=#6699cc>&nbsp;</TD>
    </TR>
    <form action="results.asp" method="post" name="form1" target="mainFrame" class="grey">
      <p><select onchange="Kermy_JS('setDynaList(arrDL1)')" name="lstOrder" id="lstOrder">
          <%
    While (NOT rsOrder.EOF)
    %>
          <option value="<%=(rsOrder.Fields.Item("Order_ID").Value)%>"><%=(rsOrder.Fields.Item("Labels").Value)%></option>
          <%
      rsOrder.MoveNext()
    Wend
    If (rsOrder.CursorType > 0) Then
      rsOrder.MoveFirst
    Else
      rsOrder.Requery
    End If
    %>
        </select> 
      Order</p>
      <p>
        <select onchange="Kermy_JS('setDynaList(arrDL2)')" name="lstFamily" id="lstFamily">
        </select> 
        Family</p>
      <p>
        <select onchange="Kermy_JS('setDynaList(arrDL3)')" name="lstGenus" id="lstGenus">
          <option value="NULL">Select Family</option>
        </select>
    Genus</p>
      <p>
        <select name="lstSpecies" id="lstSpecies">
          <option value="NULL">Select Genus</option>
        </select> 
        Species
    </p>
      <p>
        <input type="submit" name="Submit" value="Submit">
      </p>
      <p>&nbsp;</p>
    </form>
    </body>
    </html>

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Yeah, there would be a way.... when you do you on changes call another event that checks the length of the refreshed drop down box. if the lenght is 1 (or zero depending on indexing) then force the refresh or the onchange event to fire on that child.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •