PDA

View Full Version : combo boxes up to 4 levels


ventura
10-18-2002, 07:20 PM
i've been struggling with this one for a couple of days now. i hope someone can help me!

right now, this script displays a double combo box, i need to add two more for a total of 4 combo boxes. and the last selection shows text in the text box.

can someone check out this code and point me in the right direction? thanks.


<html>

<body bgcolor="white">

<form name="form" onSubmit="return false;">

<script language="JavaScript">

var num_of_cats = 4; // This is the number of categories, including the first, blank, category.

var open_in_newwindow = 1; //Set 1 to open links in new window, 0 for no.

var option_array = new Array(num_of_cats);

var str = window.document.form;



option_array[0] = new Array("You need to select a category"); // This is the first (blank) category. Don't mess with it.

option_array[1] = new Array("-- Select One --","Ears","Eyes","Mouth");

option_array[2] = new Array("-- Select One --","Thumb","Palm","Pinky");

option_array[3] = new Array("-- Select One --","Thigh","Knee","Ankle");



var text_array = new Array(num_of_cats);

text_array[0] = new Array(" "); // Instructions that show up when nothing is selected.

text_array[1] = new Array(" ", // Note that the first entry here is a general description of this category. After than, they're descriptions of each link. Make sure that you don't put the first link first; the general description must be first.

"What's wrong with your ears?",

"Eye for an eye",

"Stop mouthing off");

text_array[2] = new Array(" ", // Nothing shows up when nothing is selected yet.

"Thumb's up",

"Palm reader",

"Talk to the pinky");

text_array[3] = new Array(" ", // Nothing shows up when nothing is selected yet.

"Thigh master",

"Kneed something?",

"Swollen ankles");



var url_array = new Array(num_of_cats);

url_array[0] = new Array("#"); // The first category. This should have no items other than "#".

url_array[1] = new Array("#", // The second category; the first "real" category. Note the initial #. That is the category which says "Please select a link." It doesn't need a URL. Start putting the other URL's in after that first line.

"http://javascriptkit.com/",

"http://www.news.com/",

"http://www.wired.com/");

url_array[2] = new Array("#",

"http://www.cnn.com/",

"http://abcnews.go.com/");

url_array[3] = new Array("#",

"http://www.google.com/",

"http://www.aj.com/");



function switch_select() {

for (loop = str.select_2.options.length-1; loop > 0; loop--) {

str.select_2.options[loop] = null;

}

for (loop = 0; loop < option_array[str.select_1.selectedIndex].length; loop++) {

str.select_2.options[loop] = new Option(option_array[str.select_1.selectedIndex][loop]);

}

str.select_2.selectedIndex = 0;

}



function switch_text() {

str.textarea_1.value = text_array[str.select_1.selectedIndex][str.select_2.selectedIndex];

}



function box() {

if (str.select_2.selectedIndex == 0) {

alert("Where do you think you're going?");

}

else {

if (open_in_newwindow == 1)

window.open(url_array[str.select_1.selectedIndex][str.select_2.selectedIndex],"_blank");

else

window.location = url_array[str.select_1.selectedIndex][str.select_2.selectedIndex]

}

}



function set_orig() {

str.select_1.selectedIndex = 0;

str.select_2.selectedIndex = 0;

}

window.onload=set_orig



</script>

<textarea wrap="virtual" name="textarea_1" rows=6 cols=60></textarea>

<br>

<select name="select_1" onChange="switch_select(); switch_text();">

<option>-- Categories --</option>

<option>Head</option>

<option>Hand</option>

<option>Legs</option>

</select>

<select name="select_2" onChange="switch_text();">

<option>You need to select a category</option>

<option> </option>

<option> </option>

</select>

<input type="submit" onClick="box();" value="Go!">

</form>

</body>

</html>

jkd
10-18-2002, 08:55 PM
Perhaps http://www.geocities.com/jason_yd/4combo.html might help some?