Solved

IE8 Javascript Function Not Working

Posted on 2013-01-25
6
1,125 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 82

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now