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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:17:50+00:00 2026-05-24T01:17:50+00:00

I got a page that contain X forms, in each form there is a

  • 0

I got a page that contain X forms, in each form there is a number of checkboxes.
How do I make it so when I click on a checkbox (as displayed below), then all checkboxes in that specific form will be selected? (and un-selected if … un-checked):

I tried the following, but it does not work (name=”selectfile[]” must not be changed):
I’m not a JS king 🙁

function selectAll(){ 
    t=document.forms[0].length; 
    for(i=1; i<t-1; i++) document.forms[0][i].checked=document.forms[0][0].checked; 
} 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type='checkbox' name='checkall' style="margin-right: 15px;" onclick='selectAll(this.form.selectfile[]);'>

<input type="checkbox" name="selectfile[]" value="<? echo $file_fetch['id']; ?>" style="margin-right: 15px;" />
<input type="checkbox" name="selectfile[]" value="<? echo $file_fetch['id']; ?>" style="margin-right: 15px;" />
<input type="checkbox" name="selectfile[]" value="<? echo $file_fetch['id']; ?>" style="margin-right: 15px;" />
<input type="checkbox" name="selectfile[]" value="<? echo $file_fetch['id']; ?>" style="margin-right: 15px;" />
</form>
  • 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-24T01:17:51+00:00Added an answer on May 24, 2026 at 1:17 am
    <script type="text/javascript">
        function selectAll(val) {
            var checks = document.getElementsByName("selectfile[]");
            for (var i = 0; i < checks.length; i++) {
              checks[i].checked = val;
            }
        }
    </script>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <input type='checkbox' name='checkall' style="margin-right: 15px;" onChange="selectAll(this.checked)">
    
    <input type="checkbox" name="selectfile[]" value="<? echo $file_fetch['id']; ?>" style="margin-right: 15px;" />
    <input type="checkbox" name="selectfile[]" value="<? echo $file_fetch['id']; ?>" style="margin-right: 15px;" />
    <input type="checkbox" name="selectfile[]" value="<? echo $file_fetch['id']; ?>" style="margin-right: 15px;" />
    <input type="checkbox" name="selectfile[]" value="<? echo $file_fetch['id']; ?>" style="margin-right: 15px;" />
    </form>
    

    You can test the javascript part here: http://jsfiddle.net/protron/2t987/


    Edit: Based on your comments about having multiple forms and all the checkboxes with the same name, I updated the code and added an extra parameter to the function indicating the form index, and then used document.forms[formIndex] to get the checks. This seems to be the only easy way for this requirement without using jQuery, although IMHO it’s more error-prone this way.

    Code here: http://jsfiddle.net/protron/2t987/1/

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

Sidebar

Related Questions

I've got a simple form on a User page that allows a User, once
I got a user control containing a form. On a page that includes the
I've got a WPF tab control that contain several duplicate controls as Tab Page
Currently I've got a PHP page query.php with a form that presents a list
I've got an asp.net web form, there is an update panel that contains a
i have designed an form in that form contain button when i click on
So I have multiple forms on a page. Each form is identical except for
I've got a page that retrieves a bunch of locations and some data about
So I've got a page that shows an image with some absolutely positioned text
I've got a PHP page that parses an XML file with SimpleXml, then passes

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.