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

  • Home
  • SEARCH
  • 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 6955067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:41:19+00:00 2026-05-27T14:41:19+00:00

I am in need of making a jquery based interface where on change of

  • 0

I am in need of making a jquery based interface where on change of select causes appropriate checkeboxes to be marked. For eg I am listing Group in a drop down each group have its members. For eg group A have 5 members. Every Member is listed when A user select groupA all checkbox(5 users) checkbox will get auto selected
Here is what I have now

<?php
$groups[]= array(12 => array ( 1,2,3,4,5),13=>array ( 32,25,26),14=>array(22,23));
?>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>
function selecttheuser()
    {
      $(document).ready(function() {
        var gidet=$("select#group_id").val();
        alert(gidet);
        });
    }
</script>

<select style="width:466px" name="group_id" id="group_id" onchange="selecttheuser()">
<option value="0">Not a Group Event</option>
<option value="12">Gname</option>
<option value="13">Groupname2</option>
</select>

<input type="checkbox" value="19" class="frnzchk" name="frnzchk[]"><br>
<input type="checkbox" value="20" class="frnzchk" name="frnzchk[]"><br>
<input type="checkbox" value="21" class="frnzchk" name="frnzchk[]"><br>
<input type="checkbox" value="22" class="frnzchk" name="frnzchk[]"><br>
<input type="checkbox" value="23" class="frnzchk" name="frnzchk[]"><br>
<input type="checkbox" value="32" class="frnzchk" name="frnzchk[]"><br>
<input type="checkbox" value="25" class="frnzchk" name="frnzchk[]"><br>
<input type="checkbox" value="26" class="frnzchk" name="frnzchk[]"><br>

I have 2 problems

  1. how can I manage the PHP array it can have like 100 groups so how do I make this feasible in javascript
  2. How to select corresponding checkboxes
    Sorry If this seems straight but I donot have any idea how to approach this
  • 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-27T14:41:19+00:00Added an answer on May 27, 2026 at 2:41 pm

    Here’s how I would have solve this problem.

    First I’ll show you the working code and then I’ll explain it after.

        <?php
    
        $groups = array(
            12 => array(1, 2, 3, 4, 5),
            13 => array(32, 25, 26),
            14 => array(22, 23)
        );
    
        ?>
        <!doctype html>
        <html>
            <head>
                <meta charset="utf-8"/>
                <title>Page Title Goes Here</title>
                <style type="text/css">
                  #group_id{ width:466px; }
                </style>
            </head>
            <body>
    
                <select name="group_id" id="group_id">
                    <option value="0">Not a Group Event</option>
                    <option value="12">Gname</option>
                    <option value="13">Groupname2</option>
                </select>
    
                <?php 
                    // Loop through each group id
                    foreach(array_keys($groups) as $groupId)
                    {
                        // Create a div that can be identified by the group id
                        // to hold the checkboxes
                        $divId = 'group_' . $groupId;
                        echo '<div id="' . $divId . '">';
    
                        // Loop through each id for this particular group
                        foreach($groups[$groupId] as $choice)
                        {
                            // Create the checkbox
    
                            echo '<input type="checkbox" '
                                 .      'value="' . $choice . '" ' 
                                 .      'class="frnzchk" '
                                 .      'name="frnzchk[]"/>'
                                 . '<br/>';
                        }   
    
                        echo '</div>';
                    }
                ?>
    
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
            <script type="text/javascript">
    
                // Wait until everything is loaded 
                $(document).ready(function(){
    
                    // Bind the "change" function to the group_id drop down
                    $('#group_id').change(function(){
    
                        // Clear all of the choices
                        $('.frnzchk').attr('checked', false);
    
                        // Create the id of the div containing choices
                        var groupId = '#group_' + $(this).val();
    
                        // Check all of the choices for the appropriate group id
                        $(groupId)
                          .find('input[type="checkbox"]')
                            .attr('checked', true);
                    })
                });
    
            </script>
    
            </body>
        </html>
    

    Here’s the first chunk:

        <?php
    
        $groups = array(
            12 => array(1, 2, 3, 4, 5),
            13 => array(32, 25, 26),
            14 => array(22, 23)
        );
    
        ?>
    

    This is your list of groups and the choices associated with them. Notice when you declare the array you don’t need the square brackets i.e. $groups = array() instead of $groups[] = array().

    Next I put in all of the plumbing for a complete HTML5 page that will validate[1]. I moved your CSS out of the HTML because it makes it easier to organize, and in practice this should be moved to a completely separate CSS file.

    Here’s the next important chunk:

                <?php 
                    // Loop through each group id
                    foreach(array_keys($groups) as $groupId)
                    {
                        // Create a div that can be identified by the group id
                        // to hold the checkboxes
                        $divId = 'group_' . $groupId;
                        echo '<div id="' . $divId . '">';
    
                        // Loop through each id for this particular group
                        foreach($groups[$groupId] as $choice)
                        {
                            // Create the checkbox
    
                            echo '<input type="checkbox" '
                                 .      'value="' . $choice . '" ' 
                                 .      'class="frnzchk" '
                                 .      'name="frnzchk[]"/>'
                                 . '<br/>';
                        }   
    
                        echo '</div>';
                    }
                ?>
    

    This loops through each of your groups, and creates a DIV to hold all of the choices for that group. The div is identified by the id group_12, group_13, or group_14; The numbers come from the keys used in the $groups array.

    Next is the Javascript:

            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
            <script type="text/javascript">
    
                // Wait until everything is loaded 
                $(document).ready(function(){
    
                    // Bind the "change" function to the group_id drop down
                    $('#group_id').change(function(){
    
                        // Clear all of the choices
                        $('.frnzchk').attr('checked', false);
    
                        // Create the id of the div containing choices
                        var groupId = '#group_' + $(this).val();
    
                        // Check all of the choices for the appropriate group id
                        $(groupId)
                          .find('input[type="checkbox"]')
                            .attr('checked', true);
                    })
                });
    
            </script>
    

    I placed this all at the end of the body because Javascript runs in a single thread, so this means if you load it up front like you had it, nothing else can load until the javascript has finished loading[2]. In this example it’s not a big deal, but when you have a lot of javascript it can make a big difference!

    You’ll notice that I wrapped everything inside $(document).ready(function(){}) – this is because you don’t want it to work until everything is loaded. Since you had $(document).ready(function(){}) inside your function, every time that function gets called, it will check to see if everything is loaded, and if it’s not, then you won’t see anything happen.

    I bound the change() function to the select element, which means it will be called whenever the select element is changed, and the code inside that function will be called. We reset all of the choices, and then select all of the choices that are contained in the appropriate div.

    That should do it! Happy coding!

    [1] – http://validator.w3.org

    [2] – https://stackoverflow.com/a/1108245/1100835

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

Sidebar

Related Questions

Hi all, i'm making an application based on jQuery and i need the best
I need to set up jquery to cycle through tables, making sure it shows/hides
I'm making a slide-down login-form that is submitted with the jQuery ajax.form plugin. The
I'm making a bookmarklet and using jQuery for it (with noConflict). I need to
I need to make crossbrowser styled tags in jQuery. So instead of making clean
I need help making AOP work. What am I missing here? <?xml version=1.0 encoding=UTF-8?>
I need information about making installation packages for Linux. I want to make simple
I am making a custom control I need to add some default keybindings, microsoft
I'm making a C program where I need to get the directory that the
I am making some small business intelligence applications/tools that need to talk to other

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.