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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:06:51+00:00 2026-05-23T21:06:51+00:00

So the code I have seems correct; however, the comboboxes only change after I

  • 0

So the code I have seems correct; however, the comboboxes only change after I refresh the page; which is not what I anticipated with $.change().

Prior to the current code I had two separate ajax calls. One would clear all checkboxes, and the other would set them. This worked without a page refresh; however, sometimes would check incorrect boxes (or even not check the correct ones).

I’ve checked all the returns from the php through firebug and the results are as anticipated.

The code is with jQuery v1.5.1 because I’m using the jQuery UI.

Thanks in advance!

PHP

<?php

require 'config.php';

if(!empty($_GET['usr'])) {

    //Retrieve committee banks list
    $db->query('SELECT * FROM clas_gov_app_meeting_access_list WHERE usr="committeebank"');
    $committeebank = $db->get();

    //Retrieve selected users permissions
    $db->query('SELECT * FROM clas_gov_app_meeting_access_list WHERE usr="'. $_GET['usr'].'"');
    $accesslist = $db->get();

    //Echo user permissions
    echo $accesslist[0]['isadmin'];

    //Combine committebank's and users permissions sepereated with a slash
    $accesslist[0]['accessto'] = $committeebank[0]['accessto'] .',/,' . $accesslist[0]['accessto'];
    //Explode on commas
    $accesslist = explode(',',$accesslist[0]['accessto']);

    //Echo each value
    foreach($accesslist as $key => $value) {
        echo $value.' ';
    }
}

?>

JavaScript / jQuery

    <script type="text/javascript">
    function SetCheckboxes() {  

        var usr = $('#KUOID2').find('option:selected').val();
        $.ajax({
            url : 'ajaxLoadAccess.php?usr=' + usr,
            dataType : "text",
            success : function(response) {      


                //first char echoed is a single identifier for admin status
                var isAdmin = response.charAt(1);
                //clear that from the string
                response = response.replace(response.charAt(1), '');


                //committebank is first, and seperated from usr by a slash
                split_response = response.split("/");
                //want to clear checkboxes from the committebank and set from the usr
                ClearCheckboxes = split_response[0].split(" ");
                SetCheckboxes = split_response[1].split(" ");

                //CLEAR CHECKBOXES

                //For each value in the array
                for(var i in ClearCheckboxes) {
                    //Skipping over empty checkboxes
                    if(ClearCheckboxes[i] != '') {                              
                        //Check the boxes that need to
                        if($('input[name='+ClearCheckboxes[i]+'2]').attr('checked')) {
                            $('input[name='+ClearCheckboxes[i]+'2]').attr('checked', false);
                        }
                    }
                }

                ClearCheckboxes = [];

                //SET CHECKBOXES

                //For each value in the array
                for(var i in SetCheckboxes) {
                    //Skipping over empty checkboxes
                    if(SetCheckboxes[i] != '') {                                
                        //Check the boxes that need to
                        $('input[name='+SetCheckboxes[i]+'2]').attr('checked', true);
                    }
                }

                SetCheckboxes = [];

                if(isAdmin>0) {
                    $('input[name=isAdmin2]').attr('checked', true);
                } else {
                    $('input[name=isAdmin2]').attr('checked', false);   
                }

            }
        });
    }

$(document).ready(function() {
    $(function() {
        $( "#tabs" ).tabs();
    });

     SetCheckboxes();

     $("select").change(function() {
        SetCheckboxes();
    });
});
</script>
  • 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-23T21:06:53+00:00Added an answer on May 23, 2026 at 9:06 pm

    The highlighted lines are the culprits in your code. You are using SetCheckboxes as a variable in the same function and not using var to declare it. pLease use the below code hope it works for you.

    <script type="text/javascript">
        function SetCheckboxes() {  
    
            var usr = $('#KUOID2').find('option:selected').val();
            $.ajax({
                url : 'ajaxLoadAccess.php?usr=' + usr,
                dataType : "text",
                success : function(response) {      
    
    
                    //first char echoed is a single identifier for admin status
                    var isAdmin = response.charAt(1);
                    //clear that from the string
                    response = response.replace(response.charAt(1), '');
    
    
                    //committebank is first, and seperated from usr by a slash
                    split_response = response.split("/");
                    //want to clear checkboxes from the committebank and set from the usr
                    **var ClearCheckboxes = split_response[0].split(" ");
                    var SetCheckboxes = split_response[1].split(" ");//You should always use var to declare the js variables otherwise they are in global scope.**
    
                    //CLEAR CHECKBOXES
    
                    //For each value in the array
                    for(var i in ClearCheckboxes) {
                        //Skipping over empty checkboxes
                        if(ClearCheckboxes[i] != '') {                              
                            //Check the boxes that need to
                            if($('input[name='+ClearCheckboxes[i]+'2]').attr('checked')) {
                                $('input[name='+ClearCheckboxes[i]+'2]').attr('checked', false);
                            }
                        }
                    }
    
                    ClearCheckboxes = [];
    
                    //SET CHECKBOXES
    
                    //For each value in the array
                    for(var i in SetCheckboxes) {
                        //Skipping over empty checkboxes
                        if(SetCheckboxes[i] != '') {                                
                            //Check the boxes that need to
                            $('input[name='+SetCheckboxes[i]+'2]').attr('checked', true);
                        }
                    }
    
                    SetCheckboxes = [];
    
                    if(isAdmin>0) {
                        $('input[name=isAdmin2]').attr('checked', true);
                    } else {
                        $('input[name=isAdmin2]').attr('checked', false);   
                    }
    
                }
            });
        }
    
    $(document).ready(function() {
        $(function() {
            $( "#tabs" ).tabs();
        });
    
         SetCheckboxes();
    
         $("select").change(function() {
            SetCheckboxes();
        });
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an erlang problem, it seems. I have this code to test the
I have some code (it's part of a wordpress plugin) which takes a text
I have the following code. In windows server 2008, the program is correct and
I have an HTML page with a JavaScript code that sends AJAX request. The
Put it another way: what code have you written that cannot fail. I'm interested
We’ve found that the unit tests we’ve written for our C#/C++ code have really
Code I have: cell_val = CStr(Nz(fld.value, )) Dim iter As Long For iter =
I have code that references a web service, and I'd like the address of
I have code to create another row (div with inputs) on a button click.
I have code similar to this filtering entries in an Array of Objects: var

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.