Arrays Quirk

J

John

Hi,

I have a script where b) works perfectly but a) carries out only
select_onchange[0]. Any ideas on why? (everything else is the same,
problem in FF and IE). No errors / warnings.

John

a)

for(i=0; i<3; i++) {
select_onchange(tempArray);
}

b)

select_onchange(tempArray[0]);
select_onchange(tempArray[1]);
select_onchange(tempArray[2]);
 
J

John

Duncan said:
John wrote:

I have a script where b) works perfectly but a) carries out only
select_onchange[0]. Any ideas on why? (everything else is the same,
problem in FF and IE). No errors / warnings.

a)

for(i=0; i<3; i++) {
select_onchange(tempArray);
}

b)

select_onchange(tempArray[0]);
select_onchange(tempArray[1]);
select_onchange(tempArray[2]);



'i' is a global variable, so perhaps something in your select_onchange
function is also using the same global variable 'i' which could cause the
loop to terminate prematurely?

I suggest you make sure that your for loop is inside a function and declare
'i' as a local variable.


Fixed. Thank you very much. I naively assumed that it would work like
java. I was nowhere near fixing it until you told me that.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top