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
selectelements with the one you retrieve from your ajax call and be done with it?