views:

58

answers:

3

I have declared an array in the form:

var refs = {
 'EE810': "Presence Detector 1 Channel",
 'EE871': "Motion Detector Outdoor 220/360Deg Blk",
 'EE870': "Motion Detector Outdoor 220/360Deg WH",
 'EE811': "Presence Detector 2 Channel",
 'EE805': "Motion Detector Indoor  White Flush",
 'EE862': "Motion Detector Alum  Outdoor 220 Deg",
}

ie7 seems to consider this a syntax error as function declarations in the same script block suddenly become undefined. What's the simplest way to reformat this so it's valid in ie?

+5  A: 

One, it's an object, not an array.

Two, IE is being strict by not allowing the extra comma you have. Some parsers ignore the extra comma, but IE errors on it. Remove the comma after the last element.

strager
thanks, it's just a liitle painful as the array is initialised in a coldfusion loop. Now I'm going to have to test for the last element.
SpliFF
@SpliFF: It's usually easier to test for the _first_ element. e.g. - start with a blank delimiter in a variable, and set that variable to a ',' at the end of every iteration.
Joel Coehoorn
that wouldn't help at all in this situation, it's the last comma that's relevant. at any rate i've already written the required fix.
SpliFF
Also, it's a good idea to have a semi-colon after the closing brace.
Tim Down
+1  A: 

Don't put a comma after the final element. That's a known IE issue.

cletus
+1  A: 

IE does not permit extra commas at the end of the object. Get rid of the last comma, and it'll work.

This is one case where IE sticks to the specs. Technically, it's doing the right thing by complaining.

Charles
actually it doesn't complain at all. it simply ignores everything in the same script block. Even the developer toolbar has nothing to say. That hardly sounds correct in my book.
SpliFF