Link to home
Start Free TrialLog in
Avatar of SlickCatSeven
SlickCatSeven

asked on

IE8 Javascript Function Not Working

This function doesn't work in IE8. I've tried altering many settings in IE, but nothing works, plus, I don't know if I can get my users to change settings. So, perhaps my javascript could be better. This function toggles all the checkboxes  in a form on or off. Works in all browsers except IE8.

function toggle(source) {
  checkboxes = document.getElementsByName('prop[]');
  for(var i in checkboxes)
    checkboxes[c].checked = source.checked;
}

Mahalo for any help.
Avatar of SlickCatSeven
SlickCatSeven

ASKER

Sorry, function should be:

function toggle(source) {
  checkboxes = document.getElementsByName('prop[]');
  for(var c in checkboxes)
    checkboxes[c].checked = source.checked;
}
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmm, doesn't seem to be working. Do I need to change the checkboxes themselves?

Here is the master toggle checkbox:
<input type="checkbox" onClick="toggle(this)" />

Checkboxes look like this:
<input type="checkbox" name="prop[]" value="1" />
<input type="checkbox" name="prop[]" value="2" />
<input type="checkbox" name="prop[]" value="3" />
Combined the two answers and it works.

function toggle(source) {
  var checkboxes = document.getElementsByName('prop[]');
  var chk = source.checked;
  for(var i = 0; i < checkboxes.length; i++)
    checkboxes[i].checked = chk;
}

 Thank you for the help.
sorry. Typo

n<

should be
n=

DEMO