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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:33:15+00:00 2026-06-12T14:33:15+00:00

I am not posting here complete code yet I want an idea how to

  • 0

I am not posting here complete code yet I want an idea how to retrieve data in checboxes based on a dropdown list. I have a dropdownlist of users, and pages data in checkboxes.

Suppose table user have two columns (user_id, user) and pages have three columns (page_id, user_id, title).

I wish these cheboxes automatic check/uncheck acording to selected user without refreshing page. Suppose I am fetching users as

echo '<select name="user_id">';
echo '<option value="">Select User</option>';

$sql = "SELECT * from users";
$res = mysql_query($sql);
while($row = mysql_fetch_assoc($res)) {
    $uid = $row['user_id'];
    $user = $row['user'];
    echo '<option value="'.$uid.'">'.$user.'</option>'; 
}

echo '</select>'; 

And data in checkboxes on the basis of selected user (make sure user_id is compared in IF condition but not in query)

$user_id = $_POST['user_id']; //selected user from list

$query = "SELECT * from pages";
$result = mysql_query($query);
while($rowPage = mysql_fetch_assoc($result)) {

    $upid = $rowPage['user_id'];
    $pid = $rowPage['page_id'];
    $title = $rowPage['title'];

    if($upid == $user_id) {
        echo '<input type="checkbox" name="userPages[]" value="'.$pid.'" checked="checked"> '.$title;   
    } else {
        echo '<input type="checkbox" name="userPages[]" value="'.$pid.'"> '.$title;
    }
}

How is it possible in Ajax/Jquery I mean without refreshing page.
Hope you understand what I mean.
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-06-12T14:33:16+00:00Added an answer on June 12, 2026 at 2:33 pm

    here is the asnwer what you can do is like this

     echo '<select name="user_id" id="userCombo">';
     echo '<option value="">Select User</option>';
    
     $sql = "SELECT * from users";
     $res = mysql_query($sql);
     while($row = mysql_fetch_assoc($res)) {
        $uid = $row['user_id'];
        $user = $row['user'];
        echo '<option value="'.$uid.'">'.$user.'</option>'; 
     }
    
    echo '</select>';
    echo '<div id="userCheckBoxes"></div>'
    

    Now put the ajax call on the change event of the select box.
    I am here going to use jquery ajax.

    <script type="text/javascript">
     $(document).ready(function()
     {
       $("#userCombo").change(function()
       {
         var id=$(this).val();
         var dataString = 'user_id='+ id;
         $.ajax
         ({
             type: "POST",
             url: "ajax_checkboxes.php",
             data: dataString,
             cache: false,
             success: function(html)
             {
                $("#userCheckBoxes").html(html);
             }
         });
       });
     });
     </script>
    

    Now make ajax_checkboxes.php into same directory.
    then put your below code into the ajax_checkboxes.php. I assume you can make database connectivity and all by your self.

      $user_id = $_POST['user_id']; //selected user from list
    
      $query = "SELECT * from pages";
      $result = mysql_query($query);
      while($rowPage = mysql_fetch_assoc($result)) {
    
           $upid = $rowPage['user_id'];
           $pid = $rowPage['page_id'];
           $title = $rowPage['title'];
    
        if($upid == $user_id) {
            echo '<input type="checkbox" name="userPages[]" value="'.$pid.'"        checked="checked"> '.$title;   
         } else {
            echo '<input type="checkbox" name="userPages[]" value="'.$pid.'"> '.$title;
        }
     }
    

    I did not taste it on my local server but I am sure It will work.

    PS dont for get to include jQuery on the head section of your site.

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

Sidebar

Related Questions

My following code for posting the UIImage to user's facebook wall is not working
With my code I am clearing textbox data based on condition and trying to
I have a site problemio dot com (not posting url so it doesnt look
I have a script which is posting some form data to a Quickbase and
I have a functional page posting data to a Page WebMethod [WebMethod()] public static
I'm not a complete beginner and sorry for posting an ambiguous question that has
Found related questions but not the exact variant so I am posting a very
Okay, I feel totally stupid posting this. I am not sure if it is
On my page I have a textarea where users can enter a list of
this is my first time posting here, but I didn't know where else to

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.