Hello.
I am new to javascript and am working on dependent combo boxes. The way the original script was written it poped up an alert window with the description of what was selected. What I want to do is depending on what is selected in the "sublist" field I want to pop up a new window with a pdf and the pdf file depends on the week selected. (Ultimately I wnat different weeks listed in the sublist and whatever week is selected a pdf of the standings for that week will pop up. I have attached the code I presently have and what i've been trying to do. Any help is much appreciated.
<SCRIPT LANGUAGE=javascript>
<!--
var MainList=new Array(5);;
var SubList=new Array(13);;
//define objects for the main list
function ListItem(nvalue,description){
//function for defining the elements of the main list
this.nvalue=nvalue;
this.description=description;
}
//define objects for the dependent list
function ListSubItem(category,nvalue,description){
//function for defining the elements of the sublists
this.category=category;
this.nvalue=nvalue;
this.description=description;
}
function PrepareData(){
// the function will fill in 2 arrays. The function can be filled in ASP
// so the values from the array will come from the database
MainList[0]=new ListItem(0,"Red Crown");
MainList[1]=new ListItem(1,"Nascar");
MainList[2]=new ListItem(2,"Thur Mixec");
MainList[3]=new ListItem(3,"Independent");
MainList[4]=new ListItem(4,"YABA");
MainList[5]=new ListItem(5,"Seniors");
//Fill the values of the second list
//The first parameter is the category, the second is the value to be returned
//from this selection and the third one is the text that appears in the
//combo box
SubList[0]=new ListSubItem(0,0,"RC Week 1");
SubList[1]=new ListSubItem(0,1,"RC Week 2");
SubList[2]=new ListSubItem(0,2,"RC Week 3");
SubList[3]=new ListSubItem(0,3,"RC Week 4");
SubList[4]=new ListSubItem(1,2,"Tomato");
SubList[5]=new ListSubItem(1,3,"Cucumber");
SubList[6]=new ListSubItem(2,4,"Male");
SubList[7]=new ListSubItem(2,5,"Female");
SubList[8]=new ListSubItem(3,6,"Georgina");
SubList[9]=new ListSubItem(3,7,"Susanne");
SubList[10]=new ListSubItem(4,8,"Peter");
SubList[11]=new ListSubItem(4,9,"Paul");
SubList[12]=new ListSubItem(5,10,"Amsterdam");
SubList[13]=new ListSubItem(5,11,"Paris");
}
function reFillList(){
var selValue;
var nOption;
selValue=form1.mainlist.value;
//alert("Selected value=" +selValue);
// clear the actual list by setting its length to 0
form1.sublist.length=0
for (var i=0; i < SubList.length;i++){
//fill the box with the values corresponding to
//the category in the first box
if (SubList[i].category==selValue) {
nOption=form1.sublist.length;
form1.sublist.options[nOption]=new Option(SubList[i].description,SubList[i].nvalue);
}
}
form1.sublist.options[0].selected=true;
}
function checkvalues()
{
var val1;
var val2;
val1=form1.mainlist.value;
val2=form1.sublist.value;
if (val2=0)
{
alert("You've selected Week 1")
}
else
{
alert("not week 1")
}
//show the selected values
// var val1;
// var val2;
// var cString;
// val1=form1.mainlist.value;
// val2=form1.sublist.value;
// cString="Main List=value:" + val1 + "-Description:"+MainList[val1].description
// cString+="\n"
// cString+="Sub List=value:" + val2+ "-Description:"+SubList[val2].description
// alert(cString);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<!-- for comments on this script , contact me at ruth@zahav.net.il -->
<h1>Dependent combo boxes sample</h1>
When selecting a value from the first combo box, the<BR>
second combo box will be filled in with new values<BR>
corresponding to the selection from the first combo box<BR>
<FORM name="form1">
<SCRIPT LANGUAGE=javascript>
<!--
var page=""
var i;
// call the function that fills in the arrays so we'll use them to fill the select
PrepareData();
page+="Select the main list: ";
page+="<SELECT NAME='mainlist' onChange='reFillList()'>";
for (i=0;i<MainList.length;i++) {
page+="<OPTION VALUE="+MainList[i].nvalue;
if (i==0) {
page+=" SELECTED ";
}
page+=">"+MainList[i].description;
}
page+="</SELECT>";
document.write(page);
//-->
</SCRIPT>
           
Select SubList:
<SELECT NAME='sublist' size=4>
<SCRIPT LANGUAGE=javascript>
<!--
// since we have selected the first value in the main list, we have to fill this list
reFillList();
//-->
</SCRIPT>
</SELECT>
<P>
<INPUT type="button" value="Press me" id=button1 name=button1 onClick="checkvalues()">
</FORM>
</BODY>
</HTML>


