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

    Unanswered: Issues with multiple dynamic List Boxes

    I am trying to do multiple dynamic Menu boxes in my ASP VBscript page.

    Like this:

    Parent

    Child

    Child of Child

    I have the connection perfect from Parent to Child.

    I am not sure how to code from the Child to the ChildofChild menu box

    All of these are Menuboxes btw.

    Code:
     
    <script language="JavaScript">
    <!--
    
    var arrDynaList = new Array();
    var arrDL1 = new Array();
    
    arrDL1[1] = "Order";              // Name of parent list box
    arrDL1[2] = "form1";                      // Name of form containing parent list box
    arrDL1[3] = "family";               // Name of child list box
    arrDL1[4] = "form1";                      // Name of form containing child list box
    arrDL1[5] = arrDynaList;
      
    <%
    Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS
    
    txtDynaListRelation = "Relation"      // Name of recordset field relating to parent
    txtDynaListLabel = "Labels"            // Name of recordset field for child Item Label
    txtDynaListValue = "Values"            // 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>

  2. #2
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    Don't know if this might hopefully give you some ideas:

    Cheap Tricks 4: A Triple-Linked Listbox
    http://www.atgconsulting.com/triplelist.asp
    Uses JavaScript.
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

  3. #3
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    And I just revamped this article which now includes a sample that can be downloaded:

    ASP Design Tips - Dependent Listboxes
    http://www.bullschmidt.com/devtip-de...tlistboxes.asp
    Uses ASP.
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

  4. #4
    Join Date
    Jun 2004
    Posts
    17
    Nice article, thank you!

  5. #5
    Join Date
    Jun 2004
    Posts
    17

    Thumbs up Taking a new approach

    I decided to take a new approach rather than doing dynamic list boxes.

    I have stumbled upon the onChange javascript coding and decided I might be better off using that.

    The problem I am having now is:

    Parent

    Child

    Child2

    After the onchange- how do i pass the parent-child relationship to the child

    They both have a field called relation with the corresponding numbers. (Child-Child2 has a field called RelationChild)

    Would i have a recordset filter the relation field from form variable Parent (Which would be the one Initially selected)? Or would i have it filter the entire form itself.

    Another issue I am having is would i make the listboxes one whole form, or 3 different forms?

    Any help on this is appreciated!

  6. #6
    Join Date
    Jul 2003
    Location
    SoCal
    Posts
    721
    Check out this link.. I've use javascript and three listboxes to dynamically select an office location.. the source is on the page if you do View Source

    http://www.wellpoint.com/careers/office_locations.asp
    That which does not kill me postpones the inevitable.

Posting Permissions

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