Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:33:42+00:00 2026-06-10T03:33:42+00:00

I have 60 checkboxes with the name AG[] and i was using a check-all

  • 0

I have 60 checkboxes with the name “AG[]” and i was using a check-all function to do the job, combined with an eventlistener on buttons that were named CheckAll. Suddenly the buttons stopped working..
The select-all function is

function selectAll(a,b) {
var checkies = document.getElementsByName('AG[]');
for (var i = a;i < b;i++) {
    checkies[i].checked = !(checkies[i].checked);
    }
}

which works, because I tried onloading one run of this function.
This is the full script onload that adds the event listener on the buttons.

function script1() {
var el = document.getElementsByName('CheckAll'); 
el1 = el[0]; 
el2 = el[1];
el3 = el[2];
el4 = el[3];
el5 = el[4];
el6 = el[5];
el7 = el[6];


el1.addEventListener('click', function(){selectAll(0,8)}, false);
el2.addEventListener('click', function(){selectAll(8,16)}, false);
el3.addEventListener('click', function(){selectAll(16,26)}, false);
el4.addEventListener('click', function(){selectAll(26,34)}, false);
el5.addEventListener('click', function(){selectAll(34,44)}, false);
el6.addEventListener('click', function(){selectAll(44,52)}, false);
el7.addEventListener('click', function(){selectAll(52,60)}, false);


}

If i run the function by itself like

SelectAll(0,8);

it works, but if I do it through addeventlistener it does not.
The code was working well and I was able to check-all with buttons but i dont get what happened..
Here’s the jsfiddle jsfiddle

*Okay new problem. * the code that Andreas posted is still not working for me which probably means its because im running it from IE7, which does not support addeventlistener. So how do i make my code support firefox/chrome(Addeventlistener) and

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:33:44+00:00Added an answer on June 10, 2026 at 3:33 am

    Keeping addEventListener vs onclick in mind, the pragmatic and simple version is the following since it works in all browsers – downside as mentioned in the link is onlick supports only one event handler, while attachevent/addEventListener will fire all registered callbacks.

    DEMO

    function selectAll(a,b) {
      var checkies = document.getElementsByName('AG[]');
      for (var i = a;i < b;i++) {
        checkies[i].checked = !checkies[i].checked;
      }
    }
    function script1(){
      var el = document.getElementsByName('CheckAll');  // get all elements with that name="" attribute
      el[0].onclick=function() { selectAll(0,8) }
      el[1].onclick=function() { selectAll(8,16)}
      el[2].onclick=function() { selectAll(16,26)}
      el[3].onclick=function() { selectAll(26,34)}
      el[4].onclick=function() { selectAll(34,44)}
      el[5].onclick=function() { selectAll(44,52)}
      el[6].onclick=function() { selectAll(52,60)}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm generating several check boxes that all have the same name, when the form
I have two checkboxes. I need to check that at least one of them
I have group of checkboxes nearly equals to 100 all are with name checkbox1...checkbox1oo.
I'm using the SimpleFormController and have checkboxes in the view. When the form is
For example, i have checkboxes: <input type='checkbox' name='fruit' value='apple'> Apple <input type='checkbox' name='fruit' value='orange'>
Basically I have a set of checkboxes that are dynamically created from view data
I am creating a form with multiple checkboxes with the same name. I have
I have some checkboxes grouped using the attribute rel . When anyone is unchecked,
I have a view model with a from that includes a set of checkboxes.
i am using asp.net c# jquery vs 2008 I have two check box list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.