Hello all!
I was working using php code and then realized that I wanted to add multiple combo boxes so I found an already written javascript code and decided to use that.
However, I am using sessions and want to collect the data from what they chose to follow thru to the next few pages. I know how to have it follow thru using the states on the posted code by putting a name in <option> , but I also need the counties to follow thru and since I used this javascript code, I don't know how to do it. Any clue?
Thanks!
~Amy
<script language="JavaScript" type="text/javascript">
<!--
/*
*** Multiple dynamic combo boxes
*** by Mirko Elviro, 9 Mar 2005
*** Script featured and available on JavaScript Kit (http://www.javascriptkit.com)
***
***Please do not remove this comment
*/
// This script supports an unlimited number of linked combo boxed
// Their id must be "combo_0", "combo_1", "combo_2" etc.
// Here you have to put the data that will fill the combo boxes
// ie. data_2_1 will be the first option in the second combo box
// when the first combo box has the second option selected
// first combo box
data_1 = new Option("Alabama", "$");
data_2 = new Option("Alaska", "$$");
data_3 = new Option("Arizona", "$$$");
data_4 = new Option("Arkansas", "$$$$");
// second combo box
data_1_1 = new Option("Autauga", "-");
data_1_2 = new Option("Baldwin", "-");
data_1_3 = new Option("Barbour", "-");
data_1_4 = new Option("Bibb", "-");
data_1_5 = new Option("Blount", "-");
data_1_6 = new Option("Bullock", "-");
data_1_7 = new Option("Butler", "-");
data_1_8 = new Option("Calhoun", "-");
data_1_9 = new Option("Chambers", "-");
data_1_10 = new Option("Cherokee", "-");
data_1_11 = new Option("Chilton", "-");
data_1_12 = new Option("Choctaw", "-");
data_1_13 = new Option("Clarke", "-");
data_1_14 = new Option("Clay", "-");
data_1_15 = new Option("Cleburne", "-");
data_1_16 = new Option("Coffee", "-");
data_1_17 = new Option("Colbert", "-");
data_1_18 = new Option("Conecuh", "-");
data_1_19 = new Option("Coosa", "-");
data_1_20 = new Option("Covington", "-");
data_1_21 = new Option("Crenshaw", "-");
data_1_22 = new Option("Cullman", "-");
data_1_23 = new Option("Dale", "-");
data_1_24 = new Option("Dallas", "-");
data_1_25 = new Option("DeKalb", "-");
data_1_26 = new Option("Elmore", "-");
data_1_27 = new Option("Escambia", "-");
data_1_28 = new Option("Etowah", "-");
data_1_29 = new Option("Fayette", "-");
data_1_30 = new Option("Franklin", "-");
data_1_31 = new Option("Geneva", "-");
data_1_32 = new Option("Greene", "-");
data_1_33 = new Option("Hale", "-");
data_1_34 = new Option("Henry", "-");
data_1_35 = new Option("Houston", "-");
data_1_36 = new Option("Jackson", "-");
data_1_37 = new Option("Jefferson", "-");
data_1_38 = new Option("Lamar", "-");
data_1_39 = new Option("Lauderdale", "-");
data_1_40 = new Option("Lawrence", "-");
data_1_41 = new Option("Lee", "-");
data_1_42 = new Option("Limestone", "-");
data_1_43 = new Option("Lowndes", "-");
data_1_44 = new Option("Macon", "-");
data_1_45 = new Option("Madison", "-");
data_1_46 = new Option("Marengo", "-");
data_1_47 = new Option("Marion", "-");
data_1_48 = new Option("Marshall", "-");
data_1_49 = new Option("Mobile", "-");
data_1_50 = new Option("Monroe", "-");
data_1_51 = new Option("Montgomery", "-");
data_1_52 = new Option("Morgan", "-");
data_1_53 = new Option("Perry", "-");
data_1_54 = new Option("Pickens", "-");
data_1_55 = new Option("Pike", "-");
data_1_56 = new Option("Randolph", "-");
data_1_57 = new Option("Russell", "-");
data_1_58 = new Option("St. Clair", "-");
data_1_59 = new Option("Shelby", "-");
data_1_60 = new Option("Sumter", "-");
data_1_61 = new Option("Talladega", "-");
data_1_62 = new Option("Tallapoosa", "-");
data_1_63 = new Option("Tuscaloosa", "-");
data_1_64 = new Option("Walker", "-");
data_1_65 = new Option("Washington", "-");
data_1_66 = new Option("Wilcox", "-");
data_1_67 = new Option("Winston", "-");
data_2_1 = new Option("Aleutians East", "--");
data_2_2 = new Option("Aleutians West", "--");
data_2_3 = new Option("Anchorage", "--");
data_2_4 = new Option("Bethel", "--");
data_2_5 = new Option("Bristol Bay", "--");
data_2_6 = new Option("Denali", "--");
data_2_7 = new Option("Dillingham", "--");
data_2_8 = new Option("Fairbanks North Star", "--");
data_2_9 = new Option("Haines", "--");
data_2_10 = new Option("Juneau", "--");
data_2_11 = new Option("Kenai Peninsula", "--");
data_2_12 = new Option("Ketchikan Gateway", "--");
data_2_13 = new Option("Kodiak Island", "--");
data_2_14 = new Option("Lake and Peninsula", "--");
data_2_15 = new Option("Matanuska-Susitna", "--");
data_2_16 = new Option("Nome", "--");
data_2_17 = new Option("North Slope", "--");
data_2_18 = new Option("Northwest Arctic", "--");
data_2_19 = new Option("Prince of Wales-Outer Ketchikan", "--");
data_2_20 = new Option("Sitka", "--");
data_2_21 = new Option("Skagway-Hoonah-Angoon (North)", "--");
data_2_22 = new Option("Skagway-Hoonah-Angoon (South)", "--");
data_2_23 = new Option("Southeast Fairbanks", "--");
data_2_24 = new Option("Valdez-Cordova", "--");
data_2_25 = new Option("Wade Hampton", "--");
data_2_26 = new Option("Wrangell-Petersburg", "--");
data_2_27 = new Option("Yakutat", "--");
data_2_28 = new Option("Yukon-Koyukuk", "--");
data_3_1 = new Option ("Apache", "--");
data_3_2 = new Option ("Cochise", "--");
data_3_3 = new Option ("Coconino", "--");
data_3_4 = new Option ("Gila", "--");
data_3_5 = new Option ("Graham", "--");
data_3_6 = new Option ("Greenlee", "--");
data_3_7 = new Option ("La Paz", "--");
data_3_8 = new Option ("Maricopa", "--");
data_3_9 = new Option ("Mohave", "--");
data_3_10 = new Option ("Navajo", "--");
data_3_11 = new Option ("Pima", "--");
data_3_12 = new Option ("Pinal", "--");
data_3_13 = new Option ("Santa Cruz", "--");
data_3_14 = new Option ("Yavapai", "--");
data_3_15 = new Option ("Yuma", "--");
data_4_1 = new Option ("Arkansas", "--");
data_4_2 = new Option ("Ashley", "--");
data_4_3 = new Option ("Baxter", "--");
data_4_4 = new Option ("Benton", "--");
data_4_5 = new Option ("Boone", "--");
data_4_6 = new Option ("Bradley", "--");
data_4_7 = new Option ("Calhoun", "--");
data_4_8 = new Option ("Carroll", "--");
data_4_9 = new Option ("Chicot", "--");
data_4_10 = new Option ("Clark", "--");
data_4_11 = new Option ("Clay", "--");
data_4_12 = new Option ("Cleburne", "--");
data_4_13 = new Option ("Cleveland", "--");
data_4_14 = new Option ("Columbia", "--");
data_4_15 = new Option ("Conway", "--");
data_4_16 = new Option ("Craighead", "--");
data_4_17 = new Option ("Crawford", "--");
data_4_18 = new Option ("Crittenden", "--");
data_4_19 = new Option ("Cross", "--");
data_4_20 = new Option ("Dallas", "--");
data_4_21 = new Option ("Desha", "--");
data_4_22 = new Option ("Drew", "--");
data_4_23 = new Option ("Faulkner", "--");
data_4_24 = new Option ("Franklin", "--");
data_4_25 = new Option ("Fulton", "--");
data_4_26 = new Option ("Garland", "--");
data_4_27 = new Option ("Grant", "--");
data_4_28 = new Option ("Greene", "--");
data_4_29 = new Option ("Hempstead", "--");
data_4_30 = new Option ("Hot Spring", "--");
data_4_31 = new Option ("Howard", "--");
data_4_32 = new Option ("Independence", "--");
data_4_33 = new Option ("Izard", "--");
data_4_34 = new Option ("Jackson", "--");
data_4_35 = new Option ("Jefferson", "--");
data_4_36 = new Option ("Johnson", "--");
data_4_37 = new Option ("Lafayette", "--");
data_4_38 = new Option ("Lawrence", "--");
data_4_39 = new Option ("Lee", "--");
data_4_40 = new Option ("Lincoln", "--");
data_4_41 = new Option ("Little River", "--");
data_4_42 = new Option ("Logan", "--");
data_4_43 = new Option ("Lonoke", "--");
data_4_44 = new Option ("Madison", "--");
data_4_45 = new Option ("Marion", "--");
data_4_46 = new Option ("Miller", "--");
data_4_47 = new Option ("Mississippi", "--");
data_4_48 = new Option ("Monroe", "--");
data_4_49 = new Option ("Montgomery", "--");
data_4_50 = new Option ("Nevada", "--");
data_4_51 = new Option ("Newton", "--");
data_4_52 = new Option ("Ouachita", "--");
data_4_53 = new Option ("Perry", "--");
data_4_54 = new Option ("Phillips", "--");
data_4_55 = new Option ("Pike", "--");
data_4_56 = new Option ("Poinsett", "--");
data_4_57 = new Option ("Polk", "--");
data_4_58 = new Option ("Pope", "--");
data_4_59 = new Option ("Prairie", "--");
data_4_60 = new Option ("Pulaski", "--");
data_4_61 = new Option ("Randolph", "--");
data_4_62 = new Option ("St. Francis", "--");
data_4_63 = new Option ("Saline", "--");
data_4_64 = new Option ("Scott", "--");
data_4_65 = new Option ("Searcy", "--");
data_4_66 = new Option ("Sebastian", "--");
data_4_67 = new Option ("Sevier", "--");
data_4_68 = new Option ("Sharp", "--");
data_4_69 = new Option ("Stone", "--");
data_4_70 = new Option ("Union", "--");
data_4_71 = new Option ("Van Buren", "--");
data_4_72 = new Option ("Washington", "--");
data_4_73 = new Option ("White", "--");
data_4_74 = new Option ("Woodruff", "--");
data_4_75 = new Option ("Yell", "--");
// other parameters
displaywhenempty=""
valuewhenempty=-1
displaywhennotempty="-select-"
valuewhennotempty=0
function change(currentbox) {
numb = currentbox.id.split("_");
currentbox = numb[1];
i=parseInt(currentbox)+1
// I empty all combo boxes following the current one
while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
(document.getElementById("combo_"+i)!=null)) {
son = document.getElementById("combo_"+i);
// I empty all options except the first one (it isn't allowed)
for (m=son.options.length-1;m>0;m--) son.options[m]=null;
// I reset the first option
son.options[0]=new Option(displaywhenempty,valuewhenempty)
i=i+1
}
// now I create the string with the "base" name ("stringa"), ie. "data_1_0"
// to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill
stringa='data'
i=0
while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
(document.getElementById("combo_"+i)!=null)) {
eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex")
if (i==currentbox) break;
i=i+1
}
// filling the "son" combo (if exists)
following=parseInt(currentbox)+1
if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) &&
(document.getElementById("combo_"+following)!=null)) {
son = document.getElementById("combo_"+following);
stringa=stringa+"_"
i=0
while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {
// if there are no options, I empty the first option of the "son" combo
// otherwise I put "-select-" in it
if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
if (eval("typeof("+stringa+"1)=='undefined'"))
eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)")
else
eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)")
else
eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)")
i=i+1
}
//son.focus()
i=1
combostatus=''
cstatus=stringa.split("_")
while (cstatus[i]!=null) {
combostatus=combostatus+cstatus[i]
i=i+1
}
return combostatus;
}
}
//-->
</script>
<form>
<TR>
<TD>
<FONT style="FONT-SIZE: 11pt" face=Arial>
*State:
</FONT>
</TD>
<select name="combo0" id="combo_0" onChange="change(this);" style="width:200px;">
<option value="value1">-select-</option>
<option value="value2">Alabama</option>
<option value="value3">Alaska</option>
<option value="value4">Arizona</option>
<option value="value5">Arkansas</option>
</select>
<BR><BR>
<TR>
<TD>
<FONT style="FONT-SIZE: 11pt" face=Arial>
*County:
</FONT>
</TD>
<select name="combo1" id="combo_1" onChange="change(this)" style="width:200px;">
<option value="value1"> </option>
</select>
<BR><BR>
</form>