Solved

IE8 Javascript Function Not Working

Posted on 2013-01-25
6
1,177 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
  • 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 83

Assisted Solution

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

Accepted Solution

by:
Michel Plungjan earned 250 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
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…

749 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