Is there a way to reference different arrays from one function call?
I have 8 arrays of student names initialized as
SectA1 = new Array();
SectA1[0] = ‘Section A1’;
SectA1[1] = ‘Boop, Betty’
SectA1[2] = ‘Fudd, Elmer’;
SectA1[3] = ‘Oop, Alley’;
SectA2 = new Array();
SectA2[0] = ‘Section A2’;
SectA2[1] = ‘Bunny, Bugs’
SectA2[2] = ‘Duck, Daffy’;
SectA2[3] = ‘Mouse, Mickey’;
and 6 more arrays set with other names as follows in the <HEAD> section:
SectB1 = new Array();
SectB2 = new Array();
SectC1 = new Array();
SectC2 = new Array();
SectD1 = new Array();
SectD2 = new Array();
with different names initialized within the arrays.
This is what I also put in the <HEAD> section, but does not work:
[code=php]
function ShowSetup(Sect) {
for (i=0; i<Sect.length; i++) { tbl += Sect[i]+'<br />’; }
}
function SectionSetup(Section) {
tbl = ‘<pre>’;
if (Section == ‘a1’) { tbl += ShowSetup(SectA1); }
if (Section == ‘b1’) { tbl += ShowSetup(SectB1); }
if (Section == ‘c1’) { tbl += ShowSetup(SectC1); }
if (Section == ‘d1’) { tbl += ShowSetup(SectD1); }
if (Section == ‘a2’) { tbl += ShowSetup(SectA2); }
if (Section == ‘b2’) { tbl += ShowSetup(SectB2); }
if (Section == ‘c2’) { tbl += ShowSetup(SectC2); }
if (Section == ‘d2’) { tbl += ShowSetup(SectD2); }
tbl += ‘</pre>’;
return tbl;
}
function SetInfo(Info,Section) {
document.getElementById(Info).innerHTML = SectionSetup(Section);
}
In the <BODY> I have:
[code=php]
<a href=”#” onClick=SetInfo(‘grp’,’a1′)>A1</a>
<a href=”#” onClick=SetInfo(‘grp’,’b1′)>B1</a>
<a href=”#” onClick=SetInfo(‘grp’,’c1′)>C1</a>
<a href=”#” onClick=SetInfo(‘grp’,’d1′)>D1</a>
<a href=”#” onClick=SetInfo(‘grp’,’a2′)>A2</a>
<a href=”#” onClick=SetInfo(‘grp’,’b2′)>B2</a>
<a href=”#” onClick=SetInfo(‘grp’,’c2′)>C2</a>
<a href=”#” onClick=SetInfo(‘grp’,’d2′)>D2</a>
<div id=”grp”> </div>
My intent is to display a different set of names within the ‘grp’ <DIV> section
by passing a reference to the different array names.
I only get ‘undefined’ displayed in the <div> area.
So… is there a way to call the ShowSetup(Sect) function when the ‘Sect’ parameter is a different defined array?
I am trying to avoid using an eval() function to solve this problem.
What I want to do should be easy for someone, but not for me.
Any thoughts are welcome. ?