If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Issues with multiple dynamic List Boxes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-28-04, 16:30
jwortley jwortley is offline
Registered User
 
Join Date: Jun 2004
Posts: 17
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>
Reply With Quote
  #2 (permalink)  
Old 06-28-04, 20:20
Bullschmidt Bullschmidt is offline
Guru
 
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
Reply With Quote
  #3 (permalink)  
Old 07-07-04, 22:27
Bullschmidt Bullschmidt is offline
Guru
 
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
Reply With Quote
  #4 (permalink)  
Old 07-08-04, 17:19
jwortley jwortley is offline
Registered User
 
Join Date: Jun 2004
Posts: 17
Nice article, thank you!
Reply With Quote
  #5 (permalink)  
Old 07-09-04, 13:44
jwortley jwortley is offline
Registered User
 
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!
Reply With Quote
  #6 (permalink)  
Old 07-11-04, 00:04
Seppuku Seppuku is offline
Useless...
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On