Skip to content Skip to sidebar Skip to footer

Javascript, Script Not Working In Ie

The routine below works perfectly in Mozilla, but not in IE (I'm using 9 but have changed the compatibility mode and it's broken in 7 and 8 too). I know that it's something to do

Solution 1:

Use a proper for loop:

for (var i=0; i < document.frm_obj.elements.length; i++) {

Working demo: http://jsfiddle.net/y7xFz/1

for...in is designed to iterate over all enumerable properties of an object. document.frm_obj.elements returns a HTMLCollection, whose enumerable properties differ between browsers. In general, you shouldn't use for...in on arrays and HTMLCollections - reserve use for object maps with named properties only.

Solution 2:

Try with getAttribute() perhaps.

Solution 3:

In your code replace the below line

for (b in document.frm_obj.elements) {

with this one

for (b in document.body.getElementsByTagName("input")) { 

This way it will also work in IE.

Solution 4:

( b.type == "checkbox" )

[Also,] at_least_one_checked is defined in the local if block.

Post a Comment for "Javascript, Script Not Working In Ie"