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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:47:46+00:00 2026-05-27T03:47:46+00:00

I have the following jQuery script that is used to manage a large treeview

  • 0

I have the following jQuery script that is used to manage a large treeview of inputs with the ability to enable/disable certain inputs. When a row is enabled, its textboxes should be enabled and vice versa.

UPDATE (Working)

This is my script:

<script type="text/javascript">
    $(document).ready(function () {
        $('#cb-master').click(toggleCheckAll);
        $('#mappings input:checkbox[id^="cb"]').click(checkChildren);
        $('#mappings tbody tr[id^="child"] input:checkbox').change(toggleInputs);
    });

    function toggleCheckAll() {
        var selector = $(this).is(':checked')
                           ? '#mappings tbody input:checkbox:checked'
                           : '#mappings tbody input:checkbox:not(:checked)';

        $(selector).each(function () {
            $(this).trigger('click');
        });
    }

    function checkChildren() {
        var selector = ".child-of-" + $(this).closest('tr').attr('id');
        var isChecked = $(this).is(':checked') ? ':not(:checked)' : ':checked';
        $(selector).find('input:checkbox' + isChecked).each(function () {
            $(this).trigger('click');
            $(this).change();
        });
    }    

    function toggleInputs() {
        var isChecked = $(this).attr('checked');
        var inputs = $(this).closest('tr').find('input:text');

        if (isChecked)
            inputs.removeAttr('disabled');
        else
            inputs.attr('disabled', 'disabled');
    }
</script>

This is what my table looks like:

<table id="mappings">
    <thead>
        <tr>
            <th><input type="checkbox" id="cb-master"></th>
            <th>Title</th>
            <th>Input</th>
        </tr>
    </thead>
    <tbody>
        <tr id="grandparent">
            <td><input type="checkbox" id="cb-grandparent" /></td>
            <td>Grandparent</td>
            <td />
        </tr>
        <tr id="parent" class="child-of-grandparent">
            <td><input type="checkbox" id="cb-parent" /></td>
            <td>Parent</td>
            <td />
        </tr>
        <tr id="child-1" class="child-of-parent">
            <td><input type="checkbox" id="cb-child-1" /></td>
            <td>Child 1</td>
            <td><input type="text" /></td>
        </tr>
        <tr id="child-2" class="child-of-parent">
            <td><input type="checkbox" id="cb-child-2" /></td>
            <td>Child 2</td>
            <td><input type="text" /></td>
        </tr>
    </tbody>
</table>

This works when I manually check/uncheck each box, but it does not work when I do it programatically through the toggleCheckAll() function. Is there something I have to do to bind this event programitically as well?

Also, I am having difficulty implementing the checkChildren function recursively, as every time I attempt to I get the exception nodeName is null or not an object.

Any input is greatly appreciated. Thanks.

  • 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-27T03:47:47+00:00Added an answer on May 27, 2026 at 3:47 am

    Check out the jsfiddle

    If instead of this:

     this.checked = isChecked;
    

    try

     $(this).trigger('click');
    

    To initially disable all input text, first do:

     $('input:text').each(function(){
         $(this).attr('disabled', 'disabled'); 
     });
    

    Does that answer your question? I wasn’t able to test it out, but I assumed that by actually triggering a click event it would execute the rest of the code or instead of binding it to a click event you would bind it to a change event, that should also work.

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

Sidebar

Related Questions

I have the following jQuery script that makes an orange transparent hover effect cover
I have the following question: I am working on a JQuery script that turns
I have the following jquery function > <script type=text/javascript> > > $(document).ready(function() { >
I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I have the following script that creates a div, adds a Google Maps DOM
In script#, I have the following: jQuery.Select(#someId).Trigger(item-added, new object[]{ball} ); This compiles into the
I used the following jquery to insert a metatag into a html document. <script
I have a simple script in jQuery that works perfectly with jQuery 1.5.2 as
I have the following Javascript libraries loaded for my page. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script
I have the following HTML structure: $('#subgroup a').nextUntil('h3').wrapAll('<div></div>'); <script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script> <div id=subgroup> <h3>Group name

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.