Welcome to WebmasterWorld Guest from 107.20.34.173

Forum Moderators: open

Message Too Old, No Replies

Trouble with list index in NN7

Sorry for the newbie question

     

Kenton

7:00 am on Jul 16, 2004 (gmt 0)

10+ Year Member



Hi

I have a for loop that runs perfectly well under IE6 but does nothing under Netscape 7.1 and I was wondering if there's a work around.

I have a list called region on a form and I'm passing the form as the parameter "thisform".

During debug I've found that the script just stops at thisform.region(idx).selected - no error - just stops.

Here's the piece of code that's failing:
===========================

for (idx = 0; idx < thisform.region.length ; idx++)
{if (thisform.region(idx).selected == true)
{regions ++
};
}

===========================

any ideas
Thanks

Bernard Marx

10:27 am on Jul 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IE allows you to access some collections via ( ) notation, rather than [ ]. Netscape doesn't. So all you need to do is change (idx) to [idx]:


var idx, region = thisform.regions
for (idx = 0; idx < region.length ; idx++)
if (region[idx].selected)
regions ++

/* maybe more 'correct':

region.options[idx]
// or
region.options.item(idx) //!

*/

Kenton

12:32 pm on Jul 16, 2004 (gmt 0)

10+ Year Member



Thanks Heaps Bernard!

I should have known the problem was with IE not NN

Bernard Marx

1:19 pm on Jul 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MS doesn't need me to fight it's battles, but...
I think the problem doesn't lie with IE, rather (ahem) somewhere else ;)

..but seriously now, IE has inbuilt backward-compatibility with old methods, and features a number of convenience properties etc. Its standards support could be described as "not what it could be", but it's not that bad. In our case, IE wasn't guilty of anything other than offering an alternative.

The problem comes when people (me included) learn the IE-only techniques first, without realising (or being informed) that they are proprietary.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month