Solved

IE8 Javascript Function Not Working

Posted on 2013-01-25
6
1,191 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 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Internet is a big network which is formed by connecting multiple small networks.It is a platform for all the users which are connected to it.Internet act as platform in different fields. Such as: Internet  as a collaboration platform. Internet  as…
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 how to count occurrences of each item in an array.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

728 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