homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Trouble with list index in NN7
Sorry for the newbie question

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


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


Bernard Marx

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

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':

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



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

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)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved