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 6657265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:44:47+00:00 2026-05-26T01:44:47+00:00

I have the following code: <a href=javascript:setCheckboxes3(1); class=chkmenu>Check All</a> | <a href=javascript:setCheckboxes3(0); class=chkmenu>Uncheck All</a>

  • 0

I have the following code:

<a href="javascript:setCheckboxes3(1);" class="chkmenu">Check All</a> |
<a href="javascript:setCheckboxes3(0);" class="chkmenu">Uncheck All</a> |
<a href="javascript:setCheckboxes3(2);" class="chkmenu">Invert Selection</a><br />
<table>
<tr>
<td><input type="checkbox" name="names[8]" value="yes" />Paul</td>
<td><input type="checkbox" name="names[11]" value="yes" />Bob</td>
<td><input type="checkbox" name="names[44]" value="yes" />Tom</td>
</tr>
</table>

And the following script:

function setCheckboxes3(act)
  {
  elts = document.getElementsByName("names[]");
  var elts_cnt  = (typeof(elts.length) != 'undefined') ? elts.length : 0;
  if (elts_cnt)
    {
    for (var i = 0; i < elts_cnt; i++)
      {
      elts[i].checked = (act == 1 || act == 0) ? act : (elts[i].checked ? 0 : 1);
      }
    }
  }

The script is working with other arrays without keys, but I can’t get it to work with this array which has keys.

Thanks in advance

  • 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-05-26T01:44:48+00:00Added an answer on May 26, 2026 at 1:44 am

    You can use getElementsByClassName:

    <script type="text/javascript" language="javascript">  
    function setCheckboxes3(act) {
      var e = document.getElementsByClassName('names');
      var elts_cnt  = (typeof(e.length) != 'undefined') ? e.length : 0;
      if (!elts_cnt) {
        return;
      }
      for (var i = 0; i < elts_cnt; i++) {
        e[i].checked = (act == 1 || act == 0) ? act : (e[i].checked ? 0 : 1);
      }
    }
    </script> 
    
    <a href="javascript:setCheckboxes3(1);" class="chkmenu">Check All</a> |
    <a href="javascript:setCheckboxes3(0);" class="chkmenu">Uncheck All</a> |
    <a href="javascript:setCheckboxes3(2);" class="chkmenu">Invert Selection</a><br />
    <input type="checkbox" name="names[8]" class="names" value="yes" />Paul
    <input type="checkbox" name="names[11]" class="names" value="yes" />Bob
    <input type="checkbox" name="names[44]" class="names" value="yes" />Tom
    

    OR you can use: getElementsByTagName

    <script type="text/javascript" language="javascript"> 
    function setCheckboxes3(act) {
      var e = document.getElementsByTagName('input');
      var elts_cnt  = (typeof(e.length) != 'undefined') ? e.length : 0;
      if (!elts_cnt) {
        return;
      }
      for (var i = 0; i < elts_cnt; i++) {
        if((e[i].type) == 'checkbox') {
          e[i].checked = (act == 1 || act == 0) ? act : (e[i].checked ? 0 : 1);
        }
      }
    }
    </script> 
    
    <a href="javascript:setCheckboxes3(1);" class="chkmenu">Check All</a> |
    <a href="javascript:setCheckboxes3(0);" class="chkmenu">Uncheck All</a> |
    <a href="javascript:setCheckboxes3(2);" class="chkmenu">Invert Selection</a><br />
    <input type="checkbox" name="names[8]" value="yes" />Paul
    <input type="checkbox" name="names[11]" value="yes" />Bob
    <input type="checkbox" name="names[44]" value="yes" />Tom
    

    Did you get a chance to try jQuery?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XUL I have the following code fragments: <map name=KeypadMap> <area href=javascript:pad('A') coords=1,1,31,31
I have the following code on the my page... <a href=javascript:change_product_photo(2);><img id=alternate_product_photo_2 style=border-color:#666666; src=/v/vspfiles/photos/00-6189-2S.jpg
I have the following code, written using jQuery: var strval = '22' $(#quicknote).attr(href, javascript:location.href=/'http://site.com/notes/add?projects=/'+
Hi guys lets say I have the following html: <div class=owner> <div> <a href=javascript:void(0)
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I have the following code: <script type=text/javascript> $(document).ready(function() { $(#thang).load(http://www.yahoo.com); $(.SmoothLink).click( function() { $(#thang).fadeOut();
I have the following code that works: <script type=text/javascript> $(document).ready(function() { // Initialise the
I have the following code below in a javascript file and need to have
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section

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.