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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:01:49+00:00 2026-05-31T00:01:49+00:00

As per the requirement i have to create xhtml dynamically as described below <ul

  • 0

As per the requirement i have to create xhtml dynamically as described below

<ul class="checklist">
    <li>
        <input type="checkbox" name="level[1]" value="1" onclick="checkAll(this)" id="level[1]">
        <label for="level[1]">Unit 1</label>
        <ul class="subchecklist">
            <li>
                <input type="checkbox" checked="checked" name="courses[1][1]" value="1" onclick="checkTop()" id="courses[1][1]">
                <label for="courses[1][1]">Module 1</label>
            </li>
            <li>
                <input type="checkbox" checked="checked" name="courses[1][2]" value="2" onclick="checkTop()" id="courses[1][2]">
                <label for="courses[1][2]">Module 2</label>
            </li>

        </ul>
    </li>
        <li>
        <input type="checkbox" name="level[2]" value="2" onclick="checkAll(this)" id="level[2]">
        <label for="level[2]">Unit 2</label>
        <ul class="subchecklist">
            <li>
                <input type="checkbox" checked="checked" name="courses[2][1]" value="1" onclick="checkTop()" id="courses[2][1]">
                <label for="courses[2][1]">Module 1</label>
            </li>
            <li>
                <input type="checkbox" checked="checked" name="courses[2][2]" value="2" onclick="checkTop()" id="courses[2][2]">
                <label for="courses[2][2]">Module 2</label>
            </li>

        </ul>
    </li>
</ul>

I want to check / Uncheck all module checkboxes on the selection of its associated parent level. Here is my javascript function.

function checkAll(obj){ 
    var element = document.accessForm.elements["courses["+obj.value+"]"];   
    alert(element);     
    if(obj.checked){
        for(i=0;i<element.length;i++){
            element[i].checked = true;
        }
    }else{
        for(i=0;i<element.length;i++){
            element[i].checked = false;
        }
    }
}

But when i display element variable then get the response “Undefined”.

Can anybody please help

  • 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-31T00:01:51+00:00Added an answer on May 31, 2026 at 12:01 am

    use this function:

    function checkAll(obj){
        var element = [];
        var inputs = document.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++)
        {
            if(inputs[i].name.indexOf('courses[' + obj.value + ']') == 0)
            {
               element.push(inputs[i]);
            }
        }
    
        if(obj.checked){
            for(i=0;i<element.length;i++){
                element[i].checked = true;
            }
        }else{
            for(i=0;i<element.length;i++){
                element[i].checked = false;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an requirement as per which I have to call an existing java
I have made an application in Yii. Now as per my application requirement I
I have a requirement to create Chart like this : http://sourceforge.net/projects/ecgtoolkit-cs/ I have to
I am using SQLite C# library and as per my requirement, before going to
I'm using RichFaces per a client requirement, but the markup it (and the stock
Per this helpful article I have confirmed I have a connection pool leak in
Per a great answer from another question I have begun mounting global resources (css/js/images)
what I would like to accomplish is the following: have autocommit enabled so per
For a website implemented in Django/Python we have the following requirement: On a view
I have two generic lists of type T. Both lists contain same type, and

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.