• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Arrays

Hiya Guys,

Can anyone see where i'm going wrong?
It seems the last box doesn't want to open.
I have removed all the 'csa's as they are people

Many Thanks,

Pete:)


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="">
<Title></Title>
<SCRIPT LANGUAGE=JavaScript>

csa = new Array
csa [0] = new Array
csa [1] = new Array
csa [2] = new Array
csa [3] = new Array
csa [4] = new Array
csa [5] = new Array
csa [6] = new Array
csa [7] = new Array
csa [8] = new Array
csa [9] = new Array
csa [10] = new Array
csa [11] = new Array
csa [12] = new Array
csa [13] = new Array
csa [14] = new Array
csa [15] = new Array

//Empty
csa [0][0.0] = " "
csa [0][0.1] = " "

//A
csa [1][0.0] =  
csa [1][0.1] =

//B
csa [2][0.0] =
csa [2][0.1] =

//C
csa [3][0.0] =
csa [3][0.1] =

//D
csa [4][0.0] =
csa [4][0.1] =

//E
csa [5][0.0] =
csa [5][0.1] =

//F
csa [6][0.0] =
csa [6][0.1] =

//G
csa [7][0.0] =
csa [7][0.1] =

//H
csa [8][0.0] =
csa [8][0.1] =

//I
csa [9][0.0] =
csa [9][0.1] =

//J
csa [10][0.0] =
csa [10][0.1] =

//K
csa [11][0.0] =
csa [11][0.1] =

//L
csa [12][0.0] =
csa [12][0.1] =

//M
csa [13][0.0] =
csa [13][0.1] =

//N
csa [14][0.0] =
csa [14][0.1] =

//O
csa [15][0.0] =
csa [15][0.1] =

function FillList()
{
var num=document.formname.team.selectedIndex
var boxlength = 0

document.formname.csa.selectedIndex = 0
for ( ctr=0;ctr<reasons[num].length;ctr++)
 {
 boxlength++;
 document.formname.csa.options[ctr] = new Option(csa[num] [eval(ctr + ".1")], csa[num][eval(ctr + ".0")]);
 }

document.formname.csa.length = boxlength;
document.formname.csa.options.length = boxlength;
document.formname.csa.focus() ;

}

</SCRIPT>
</HEAD>
<BODY>
<FORM action="" method=post id=form1 name=formname>
<SELECT id=select1 name=team onChange="JavaScript:FillList()">
<OPTION value=""></OPTION>
<OPTION value=A>A</OPTION>
<OPTION value=B>B</OPTION>
<OPTION value=C>C</OPTION>
<OPTION value=D>D</OPTION>
<OPTION value=E>E</OPTION>
<OPTION value=F>F</OPTION>
<OPTION value=G>G</OPTION>
<OPTION value=H>H</OPTION>
<OPTION value=I>I</OPTION>
<OPTION value=J>J</OPTION>
<OPTION value=K>K</OPTION>
<OPTION value=L>L</OPTION>
<OPTION value=M>M</OPTION>
<OPTION value=N>N</OPTION>
<OPTION value=O>O</OPTION>

</SELECT>

<p>
<SELECT id=select2 name=csa>
<OPTION></OPTION>
</SELECT>
0
PeterHing
Asked:
PeterHing
1 Solution
 
BatalfCommented:
Use for/in to iterate your array. This is needed because of your indexes 0.0, 0.1

Example:


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="">
<Title></Title>
<SCRIPT type="text/javascript">

csa = new Array
csa [0] = new Array
csa [1] = new Array
csa [2] = new Array
csa [3] = new Array
csa [4] = new Array
csa [5] = new Array
csa [6] = new Array
csa [7] = new Array
csa [8] = new Array
csa [9] = new Array
csa [10] = new Array
csa [11] = new Array
csa [12] = new Array
csa [13] = new Array
csa [14] = new Array
csa [15] = new Array

//Empty
csa [0][0.0] = "Test "
csa [0][0.1] = "Testing "

//A
csa [1][0.0] = "A test"
csa [1][0.1] = "Another test " 

//B
csa [2][0.0] =" " 
csa [2][0.1] =" " 

//C
csa [3][0.0] = " "
csa [3][0.1] = " "

//D
csa [4][0.0] = " "
csa [4][0.1] = " "

//E
csa [5][0.0] = " "
csa [5][0.1] = " "

//F
csa [6][0.0] = " "
csa [6][0.1] = " "

//G
csa [7][0.0] = " "
csa [7][0.1] = " "

//H
csa [8][0.0] = " "
csa [8][0.1] = " "

//I
csa [9][0.0] = " "
csa [9][0.1] =" " 

//J
csa [10][0.0] = " "
csa [10][0.1] = " "

//K
csa [11][0.0] = " "
csa [11][0.1] = " "

//L
csa [12][0.0] = " "
csa [12][0.1] = " "

//M
csa [13][0.0] = " "
csa [13][0.1] = " "

//N
csa [14][0.0] = " "
csa [14][0.1] = " "

//O
csa [15][0.0] = " "
csa [15][0.1] = " "

function FillList(num)
{
    document.formname.csa.options.length=0;
    document.formname.csa.selectedIndex = 0
    self.status  = num + "|" + csa[num].length;
    for(var prop in csa[num]){
        document.formname.csa.options[document.formname.csa.options.length] = new Option(csa[num] [prop], csa[num][prop]);    
       
    }
    document.formname.csa.focus() ;

}

</SCRIPT>
</HEAD>
<BODY>
<FORM action="" method=post id=form1 name=formname>
<SELECT id=select1 name=team onChange="JavaScript:FillList(this.selectedIndex)">
<OPTION value=""></OPTION>
<OPTION value=A>A</OPTION>
<OPTION value=B>B</OPTION>
<OPTION value=C>C</OPTION>
<OPTION value=D>D</OPTION>
<OPTION value=E>E</OPTION>
<OPTION value=F>F</OPTION>
<OPTION value=G>G</OPTION>
<OPTION value=H>H</OPTION>
<OPTION value=I>I</OPTION>
<OPTION value=J>J</OPTION>
<OPTION value=K>K</OPTION>
<OPTION value=L>L</OPTION>
<OPTION value=M>M</OPTION>
<OPTION value=N>N</OPTION>
<OPTION value=O>O</OPTION>

</SELECT>

<p>
<SELECT id=select2 name=csa>
<OPTION></OPTION>
</SELECT>
</BODY>
</HTML>
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now