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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top