Solved

Lists & Combos

Posted on 2000-05-08
2
162 Views
Last Modified: 2013-12-25
Is there a way to filter a combo list based on the selection of another combo list without revisting the server and that works in both IE 4+ and Netscape 4+?



0
Comment
Question by:mshire
2 Comments
 
LVL 8

Accepted Solution

by:
xabi earned 100 total points
ID: 2795707
Here goes an example:

--------- 8< --------- 8< ----------
<html>
<head>
<title>Example</title>
<script language="javascript">
<!--
var aOptions = new Array()
aOptions["1_"]     = "Fruit"
aOptions["1_1_"]   = "Fruit Orange"
aOptions["1_2_"]   = "Fruit Apple"
aOptions["1_1_1_"] = "Fruit Orange Good"
aOptions["1_1_2_"] = "Fruit Orange Bad"
aOptions["1_2_1_"] = "Fruit Apple Green"
aOptions["1_2_2_"] = "Fruit Apple Red"
aOptions["1_2_3_"] = "Fruit Apple Yellow"

aOptions["2_"]     = "Color"
aOptions["2_1_"]   = "Color Red"
aOptions["2_2_"]   = "Color Blue"
aOptions["3_3_"]   = "Color Green"
aOptions["2_1_1_"] = "Color Red Dark"
aOptions["2_1_2_"] = "Color Red Light"
aOptions["2_2_1_"] = "Color Blue Dark"
aOptions["2_2_2_"] = "Color Blue Light"
aOptions["2_3_1_"] = "Color Green Dark"
aOptions["2_3_2_"] = "Color Green Light"

aOptions["3_"]     = "Number"
aOptions["3_1_"]   = "Number Big"
aOptions["3_2_"]   = "Number Small"
aOptions["3_1_1_"] = "Number Big 1000"
aOptions["3_1_2_"] = "Number Big 2000"
aOptions["3_1_3_"] = "Number Big 3000"
aOptions["3_2_1_"] = "Number Small 2"
aOptions["3_2_2_"] = "Number Small 5"
aOptions["3_2_3_"] = "Number Small 9"

function level(sTmp) {
 iTmp = 0
 for (i=0; i<sTmp.length; i++) {
  if (sTmp.charAt(i) == "_") iTmp++
 }
 return iTmp
}

function redo_level3() {
 idselect = document.myform.myselect3
 idselect.length = 0
 if (document.myform.myselect2.selectedIndex != -1) {
  sTmp = document.myform.myselect2.options[document.myform.myselect2.selectedIndex].value
 } else {
  if (document.myform.myselect1.selectedIndex != -1) {
   sTmp = document.myform.myselect1.options[document.myform.myselect1.selectedIndex].value
  } else {
   sTmp = ""
  }
 }
 for (sName in aOptions) {
  if ((level(sName) == 3) && (sName.substr(0,sTmp.length) == sTmp)) {
   idselect.length++
   idselect.options[idselect.length-1].value = sName
   idselect.options[idselect.length-1].text  = aOptions[sName]
  }
 }
}

function redo_level2() {
 idselect = document.myform.myselect2
 idselect.length = 0
 if (document.myform.myselect1.selectedIndex != -1) {
  sTmp = document.myform.myselect1.options[document.myform.myselect1.selectedIndex].value
 } else {
  sTmp = ""
 }
 for (sName in aOptions) {
  if ((level(sName) == 2) && (sName.substr(0,sTmp.length) == sTmp)) {
   idselect.length++
   idselect.options[idselect.length-1].value = sName
   idselect.options[idselect.length-1].text  = aOptions[sName]
  }
 }
 redo_level3()
}

function redo_level1() {
 idselect = document.myform.myselect1
 idselect.length = 0
 for (sName in aOptions) {
  if (level(sName) == 1) {
   idselect.length++
   idselect.options[idselect.length-1].value = sName
   idselect.options[idselect.length-1].text  = aOptions[sName]
  }
 }
 redo_level2()
}

//-->
</script>
</head>
<body onload="redo_level1()">
 <form name="myform">
  <select name="myselect1" size="4" onchange="redo_level2()">
  <option>--------------------------------------------------------------</option>
  </select>
  <br><br>
  <select name="myselect2" size="4" onchange="redo_level3()">
  <option>--------------------------------------------------------------</option>
  </select>
  <br><br>
  <select name="myselect3" size="4">
  <option>--------------------------------------------------------------</option>
  </select>
 </form>
</body>
</html>
---------- 8< ----------- 8< ---------

If you need more info just ask.

xabi
0
 

Author Comment

by:mshire
ID: 2799736
With a little alteration, I managed to get it to work the way I wanted... I've just got to try it out on Netscape. Thanks.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question