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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:17:47+00:00 2026-06-01T21:17:47+00:00

I am just starting out with javascript so please pardon me if my question

  • 0

I am just starting out with javascript so please pardon me if my question seems stupid. I want to design a webpage with some checkboxes such that when the first one is checked, the others become enabled. How do I do that using JS? I wrote the following code:

function checkBox() {
    if (window.document.form1.mainbox.checked=true) {
        for (i=0;i<window.document.form1.Others.length;i++) {
            window.document.form1.Others[i].disabled=false;
        }
    }
    else {
        for (i=0;i<window.document.form1.Others.length;i++) {
            window.document.form1.Others[i].disabled=true;
        }
    }
}

And this html:

<form name="form1">
<input name="mainbox" value="mainbox" onclick="checkBox()" type="checkbox"> Mainbox<br>
<input disabled="disabled" checked="checked" tabindex="0" name="Others"   type="checkbox">No. 1<br>
<input disabled="disabled" checked="checked" tabindex="1" name="Others" type="checkbox"> No. 2<br>
<input disabled="disabled" checked="checked" tabindex="2" name="Others" type="checkbox"> No. 3<br>
</form>

The problem is that on the first click the other checkboxes do become enabled, but nothing happens on the subsequent clicks, i.e. they do not become disabled again. How do I correct this problem? Any help will be appreciated. Thanks!

EDIT

I followed the suggestion of gabitzish and it worked. However, I now want to pass Others as a parameter, so I write:

<input name="mainbox" value="mainbox" onclick="checkBox(Others)" type="checkbox"> Mainbox<br>

and modify the script as follows:

window.checkBox = function(chkname) {
    if (window.document.form1.mainbox.checked==true) {
        for (i=0;i<window.document.form1.chkname.length;i++) {
            window.document.form1.chkname[i].disabled=false;
        }
    }
    else {
        for (i=0;i<window.document.form1.chkname.length;i++) {
            window.document.form1.chkname[i].disabled=true;
        }
    }
}

But this does not work. Please help me out here. I will be very thankful.

  • 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-01T21:17:49+00:00Added an answer on June 1, 2026 at 9:17 pm

    I’ve created a jsFiddle with your code, and some minor changes : http://jsfiddle.net/CUeDg/1/

    The problem with the original code was that checkBox() function was not found on click.

    Edit:
    Here is a solution to later edit of your question: http://jsfiddle.net/CUeDg/3/
    I’ve passed the param to the function as a string.

    Later edit:
    I suspect that you need that param to know what set of checkboxes you need to toggle. I made a jsFiddle for that too: http://jsfiddle.net/CUeDg/5/
    (If I suspected wrong, don’t consider this part of the answer)

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

Sidebar

Related Questions

First off, please bear with the question as I am just starting out with
I'm just starting out with Knockout (and javascript for that matter). The problem is
I'm just starting out learning javascript, and tried to write a little script that
I'm just starting out with jQuery and want to use $(document).ready() to dynamically generate
im just starting out with javascript so go ez on me. i have an
I'm just starting out with Paypal, so this is a newbie question. I've been
Just starting to get the hang of MVC3 and want to start building out
I'm just starting out with jQuery. I want to send JSON data to a
I just starting out in C++ and I've reached a problem in some practice
I am just starting out learning JavaScript and I have just reach the DOM

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.