Click to See Complete Forum and Search --> : dynamic for loop


dot
09-07-2003, 10:53 AM
i have this :


for (i = 0; i < test.length; i++)
{
document.write("#" + test[i].number + test[i].name + test[i].height +
test[i].position + test[i].college + "<br>")
}


my question is how can i make 'test' dynamic ? so that i can specify for
example through a form which array (the name) it should be?

tnx

gil davis
09-07-2003, 11:04 AM
You maen something like this?

function dynamic(test) {
for (i = 0; i < test.length; i++)
{document.write("#" + test[i].number + test[i].name + test[i].height + test[i].position + test[i].college + "<br>") }
}
...
dynamic(document.form1);
dynamic(document.form2);
dynamic(document.form3);
...

If you show some example form HTML, it would make more sense to us.

dot
09-07-2003, 11:35 AM
no :D
i have this :

<script language="JavaScript">
<!--
function player(number,name,position,height,college)
{
this.number = number
this.name = name
this.position = position
this.height = height
this.college = college
}

var menu1 = new Array(5)
menu1[0] = new player("20","Gary Payton","Guard"," 6'4","Oregon State")
var menu1_1 = new Array(2)
menu1_1[0] = new player("21","Pete Payton","Guard"," 6'4","Oregon State")
menu1_1[1] = new player("22","John Payton","Guard"," 6'4","Oregon State")
menu1[1] = new player("33","Hersey Hawkins","Guard"," 6'3","Bradley")
menu1[2] = new player("42","Vin Baker","Forward"," 6'11","Hartford")
menu1[3] = new player("11","Detlef Schrempf","Forward"," 6'10"," Washington")
menu1[4] = new player("22","Jim McIlvaine","Center"," 7'1"," Marquette")

for (i = 0; i < test.length; i++)
{document.write("#" + test[i].number + test[i].name + test[i].height + test[i].position + test[i].college + "<br>") }

</script>

when clicking a button : "menu1"
i want "test" to be the name "menu1"
and when clicking a button : "menu1_1"
i want "test" to be the name "menu1_1"

so how can i make the "test" in my for loop dynamic...variable ?