Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

IE8 Javascript Function Not Working

Posted on 2013-01-25
6
Medium Priority
?
1,216 Views
Last Modified: 2013-01-26
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.
0
Comment
Question by:SlickCatSeven
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Author Comment

by:SlickCatSeven
ID: 38821429
Sorry, function should be:

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

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 1000 total points
ID: 38821495
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1000 total points
ID: 38821594
You do not use for in with collections or arrays

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

Open in new window

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 

Author Comment

by:SlickCatSeven
ID: 38822585
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" />
0
 

Author Closing Comment

by:SlickCatSeven
ID: 38822608
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38822613
sorry. Typo

n<

should be
n=

DEMO
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question